# Cubic interpolation, velocity and rotation

As Sam mentioned, the problem with using the velocity to determine the rotation is that, when going in reverse, the algorithm has no way to know that we are reversing and the car would always point towards the movement direction.

But I think it’s worth pointing that the same applies for the position and derivative/velocity as well. If the StartVelocity is forward and the TargetVelocity is backward (or vice-versa), the curve will be incorrect. It will be smooth, when in reality there should be a singular point when the direction changes:

In blue is the path followed by the controller car.
In red is the path followed by the interpolation.
One arrow is “forward”, the other is “reverse” (doesn’t matter which)

In practice, it’s unlikely to be an issue since, to be noticeable, it would require quick changes of speed and slow network updates, which shouldn’t be a common combination. With slow speed changes and/or fast network updates, the speed at one or both endpoints is going to be near 0 anyway so there wouldn’t be much of a singular point.
But still, I think it’s worth keeping the possibility in mind.

1 Like

I agree with this. I’ve spent so much time thinking that there must be a better way of doing this and there has to be. Take games like Forza Horizon, or indeed any online racing games in particular. You very rarely experience glitches so either they update very frequently or they have brilliant simulations set up. Probably both.

Indeed, I’m thinking that there must be something better at least for players (for other actors, that could be good enough). One thing I particularly dislike with the solution is the added latency. Now, not only we have the network latency to deal with, but we also have to wait for a second update before moving the car and stays one step behind.

To work around the latency, I think it might be possible to use the spline using an extrapolated position rather than having to wait for the next update.

For cars that should be enough. Since they are so heavy, they can’t change speed/direction very quickly. This is doubly true for realistic racing games, since they also have to deal with the car inertia on top of that (and maybe the fact that the steering wheel cannot go from -1 to 1 instantly, although it can still be pretty quick on a race car compared to a civilian car).

1 Like