Motion with constant speed along a spline with a variable length in real time

I have an object that must move along the spline at a constant speed, regardless of the position of the end point of the spline. Endpoint coordinates may vary during the process.
As a test, I attach the last (or intermediate) spline point to the mouse cursor.
How to realize a constant speed, regardless of the length of the spline and the time of movement from beginning to end?

something like that?. if so, it does not work correctly…

On tick, you can add X to a variable ( initially zerl ), which is then use as distance along the spline. Also, each tick, move the object to that point on the spline. A value of 1 would do the trick to start with. You also need to multply the variable by the delta time, otherwise the object will move at different rates depening on the machine spec.

So, you’re always adding a fixed amount to your var, it’s not a proportion of distance on the spline. If the result is ever greater than the spline length, you can just reset it.

That looks ok, gimme a little while, I’ll post something up…

285962-spline.gif

Code is:

( distance = 5, speed = 250 )

( might be factoring the speed at the wrong point though, just checking… )

Naaa, it’s ok :slight_smile:

( ahh, you had ‘local’ on the spline distance… )

285977-2019-08-27-14-19-43.gif

This is how it looks.

Does it matter?

Yes. Local coords not being the same as world.

I also tried moving the end of my spline while the ball was moving. Still works. Must be something else you have going on… :wink:

How do you mean ‘attach second point to mouse cursor’?

Understand. But but in this case the problem is not that.

Try to make 3 spline points, and attach second point to you mouse cursor, then check it…

Put it on Tick’s.

No, the object travels clearly along the spline, just the spline itself changes not only after the object, but also before. You can verify this by entering the command in the console: show splines

It turns out that you need to fix the already traveled path in some way.

This is the question of how to do it differently so that it works as planned…

Tried it, really weird behaviour. But I think that’s because it just can’t figure out where it’s supposed to be on the spline…

Nope, how I can see the spline it is working fine, even with the second point… will try and make a vid…