Navigate Curve at Constant Speed

Hi, all!

I’ve seen and read a lot of threads concerning iTween and traversing through paths at a constant speed. I have an example up and running right now that works perfectly, moving all objects around a curve at a constant rate.

The path in question is a flat oval (Much like a running track). For an object placed directly on a path, this works perfectly. I can have it move at, say, 15 units per second and it’ll do that.

However, when I incorporate an offset with the curve, all objects sitting on the offset complete the curve in the same amount of time, because the math is tied to a time and not a speed in reality. It simply takes the speed and divides it by the length of the base curve and multiplies that by delta time. So although it purports to operate at a consistent speed, this is not quite true.

I know this because if I change the path length math to update the length in the equation based on the offset, it operates perfectly as a state function, but not in between start and end. As in; when a full revolution is complete, all of the objects are where they should be. But the spaces between them occur over the course of the run.

This should not be happening. The advances in spacing should technically only occur on the curves of the oval and not the straight sides, because when they are all moving at the ‘same speed’ in a straight line, no advances should be made.

I don’t quite know how to deal with this. The code I borrowed from another thread works mainly with iTween Path Length and PutOnPoint functions.

I’ve gotten as far as calculating the maximum number of units an object should be able to travel in a given FixedUpdate. The next step should be to find what point on the curve from the current point is that number of units away. I am versed in calculus and am not afraid to use it but I am not quite sure about how to construct an algorithm to represent the curve.

Any help would be appreciated.

TL;DR: I want to move something along a curve in a way that keeps it at a steady units/second, taking into account any offset from the curve.

Thanks! - YA

I’m afraid I can’t offer you an answer from experience yet, but since it appears you’re looking to measure the length of bezier curves, I believe that you may be able to find the answers you’re looking for between here and here.

From what I’ve seen of the tweening libraries, the curved paths are actually just a series of waypoints close enough together that they approximate the curve. If you find yourself needing to change the curve dynamically and update the speed you could always switch to a tweening function based on time and calculate the speed yourself based on the length of your new curve. All you’d need is the sum of the linear distance of the waypoints divided by your desired speed to give you the time used in the tween.

So I figured it out by doing this:

Do some percentage math to clamp the distance travelled pretty close to what you want.
Do math to find the exact distance you actually want to travel.
Get the normalized vector in that direction and travel that exact distance.

Done :slight_smile: Works like a charm.