# How to move an object linearly along a bezier spline

Hi, I am creating a bezier spline implementation that works via the DeCasteljau algorithm, the algorithm works as intended, but the tessellation (spacing between points produced by the curve algorithm) isn’t linear. In order to move a vehicle or object along the path at a consistant, controllable speed in runtime I need a way to either change the tessellation whether by another algorithm or a helper function. Does anyone have or know anything that can help me? My curve system has nodes, each node consists of four transforms, pointA controlA controlB and pointB, the algorithm returns a point from a to b using the control points to define the curve. Any help will be appreciated, I’ve done so much research my head hurts so I need some help, thanks.

The basic technique is, as a pre-processing step, to evaluate your curve for lots of small steps of your input parameter. With each step evaluated calculate the distance between the point returned and the previous point returned and add this to a total distance variable you keep track off as you go along. Then put all these distances and corresponding input values for each distance into a table and store this table somewhere.

When your game is running you can keep track of a distance variable for each object that is following the spline which you store inside your object. Each update you then increment the objects distance variable according to its speed and then look up this distance in your table you pre-calculated earlier to figure out the appropriate input value for your curve. To get the position of your object you then evaluate your curve using the looked up input parameter.

This will allow your object to move along the spline at a constant speed.

What I’ve described above is a quick overview of the technique. For a more detailed discussion with associated maths, take a look at this tutorial I wrote for shmupdev a while back. Unfortunately the pictures are now missing since the site got archived and the tutorial deals with catmul-rom splines rather than bezier but you should be able to work it out. Just replace the catmul-rom equations for your bezier equations and the rest should be exactly the same.

I hope that helps.