Acceleration in Unity

后端 未结 4 2276
予麋鹿
予麋鹿 2021-02-20 04:38

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

4条回答
  •  轮回少年
    2021-02-20 05:33

    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() :)

提交回复
热议问题