I am trying to emulate acceleration and deceleration in Unity.
I have written to code to generate a track in Unity and place an object at a specific location on the trac
As far as I can tell you already have most of the solution in, just initialized improperly.
The local speed is dependent on the length of the spline, so you should modulate the speed by the inverse of the length of the segment (which you can easily approximate with a few steps).
Granted, in your case you don't have control over the speed, only the input time, so what you need is to distribute properly the values of SimpleWayPoint.time
according to the order and length of previous spline segments, instead of initializing it manually in the field declaration. This way percentageThroughSegment
should be evenly distributed.
As mentioned in comments, some of that math could look simpler with Lerp()
:)