 # BezierTo does not move at constant speed

Using BezierTo on a Sprite I note that it moves at different speeds at different places on the curve. Any solutions for this?

I have a path made up of curves, for each curve I calculate the length and then use that length to calculate the time. However it is on an individual curve defined in BezierTo that the sprite slows down and speeds up.

I’ve demoed this in the video below setting the curve as a straight line. You do this by setting control point 1 to the end and control point 2 to the beginning with a time of 2 seconds. The sprite gets slower the closer to the middle it gets until almost stops. Settings the points to be equally distanced along the line solves this for Bezier straight lines, but I’m not using Bezier curves for lines, this same behaviour is exhibited on curves and this is problematic.

Example of not constant speed on a curve. A bit hard to see but the sprite picks up a bit of speed when hitting the curve in the centre of the screen.

This is the resulting behaviour of Bezier curve maths for getting the X and Y points at a percentage of the complete curve, 0% being the start point and 100% being the end point of the curve and all other percentages being the points in between. Cocos2d works by getting the current X and Y with the percentage being the time passed since starting the move and the total time the entire move will take. So 5 seconds into a 10 second move will get the point at 50%.

Hi, I’m new to Cocos and to these forums, but not new to coding. Unfortunately moving at a constant speed, or creating equidistant points along a Bezier is a bit more complicated. You have to work out a series of points along the curve first and then interpolate along that, which means you probably only want to work out all the points once up front and store them. Some Bezier libraries will support this usage out of the box. There is a good tutorial / explanation on youtube, it’s for unity, but the language is pretty similar… edit I’m not allowed to link it but if you search “Sebastian Lague bezier curve editor” on YT you should find it easily.

Thanks. This is what I did in the end, went over the curve and pre-calculated the points along it using the length through the curve as t.