# Using Hermite Spline Interpolation For Movement

It is supposed to to take velocity into account when moving.

But I cant seem to figure out how to use to move a transform thru a list of data points.

Yo @Deltakosh or @sebavan or anybody really… Could you please show me how to use hermite spline interpolation so i can get some smooth movement between data points… Pretty Please

Hi MackeyK24,

In case you haven’t run across them before, the Hermite splines Babylon has built-in are called Catmull-Rom splines. It doesn’t look like the we provide a way to directly specify velocity or extend to arbitrary dimensionality, but if what you’re looking to do is just smoothly interpolate through a set of 3D points, this should do the trick. Hope this helps, and best of luck!

1 Like

I am actually trying to use it to smoothly interpolate network position updates. I dont know of a way to account for velocity when just simple lerping catmull rom positions… That is what lead me to hermite interpolation… its was suppose to practically made for networking smooth interpolation with velocity… I just dont know how to use it

Hey there Mackey! Splines are def a… twisty subject (terrible joke, I know ). Can you talk a little bit more about what you want to achieve? You have a list of points with position and velocity specified on each one of them?

2 Likes

Yes… and I want to smoothly between points

Hey @MackeyK24 ,

I believe no matter what way of generating the curve you choose it will be giving you a sequence of points in space and it is going to be up to you how you interpolate between them.

One solution might be to use any of the methods in BABYLON.Curve3 to generate the array of position between your points and than place them all into an animation. You can control the velocity the object will have along the curve by carefully adjusting the frame parameter in the animation.

Here is a playground example:
Babylon.js Playground (babylonjs-playground.com)

You could even use the delta position between the points the the curve the calculate the target frame in order to achieve a desired velocity.

2 Likes

@MackeyK24 in your quest for AAA networking, one suggestion I could give is read Torque3D open source engine code for networking to see how they did it. I have been in there long ago and it’s DENSE though.

They use movement vectors but not for splines. `interpolateTick` is the function you want to chase around there.

The Move structure is a 32 millisecond snapshot of player input, containing x, y, and z positional and rotational changes as well as trigger state changes. When time passes in the simulation moves are collected (depending on how much time passes), and applied to the current control object on the client. The same moves are then packed over to the server in GameConnection::writePacket(), for processing on the server’s version of the control object.

1 Like

Sorry, forgot to reply to this yesterday.

Catmull-Rom splines are a type of Hermite spline, so the behaviors you’ll see from them are very similar to the behaviors you’ll see from other Hermite splines. The reason I brought up arbitrary dimensionality is because I believe one way to achieve what you’re looking for — the incorporation of velocity — is to use a spline in a higher-dimensional space. For example, if your network updates send you position, orientation, and linear velocity, you could interpolate amongst all of those at once in a single nine-dimensional Catmull-Rom spline. There are plenty of gotchas with this (scaling is an issue, and I definitely wouldn’t recommend lumping rotation in there because of complexities with zero-crossings), but essentially it boils down to using your splines to interpolate through something other than Euclidean “positional” space: you could interpolate in “velocity” space by itself, “position” and “velocity,” etc. I did something similar years ago to generate river paths in procedural terrain, incorporating flow flow volume as a fourth dimension.

Long story short, I believe Catmull-Rom splines can help you interpolate smoothly any space with any usage, not just 3D positions.

So i am trying to incorporate velocity directly in the interpolation process. So instead of LERPING from origin position to target position where the T value is basically the InverseLerp (percentage of the current time between start and stop timestamps).

I track linear velocity and interpolate the current velocity and use that in the interpolation to
MoveTowards the target position from the current transform position (not origin position)

FYI… I made a MoveTowards function like Unity and Godot have a Vector3.MoveTowards.

Now the trick is making sure to get accurate velocity tracking over the network. When other forces are controlling the client movement… IE… Character controller is actually moving the local client transform.

I am still working on smoothing out network movement