- Home /
How to move object along Spline at constant speed?
So I'm trying to move something along a spline at a constant, as objects speed up and slow down at specific points on the spline if I move them normally. I've managed to glean some information and got partway there. I have couple of methods where I can reasonably calculate the length of two points on the spline and another method where I can calculate a consistent. I can use these to place objects at consistent equidistant points on the spline but I cant quite figure out how to use them to move objects along the spline at a consistent which is frame rate independent. Here's an example of the code I can use to place objects along the spline at consistent points and it works.
for (int i = 0; i <= numofpoints; i++)
{
Entity curent = EntityManager.Instantiate(Prefabinator.TestIntervalPrefab);
currbezpos = calcBezier.Execute(ref currentBezier, curensplinepos);
EntityManager.SetComponentData(curent, new Translation { Value = currbezpos });
EntityManager.SetName(curent, "Thepointsonspline");
curensplinepos = calcdistomove.Execute(ref currentBezier, 2.5f, curensplinepos);
}
Basically calcdistomove gets the current place on the spline and a specified distance and then returns the place on the spline at that distance from the original place on the spline. I guess I don't really understand how to use it. I've tried lots of different ways of moving things but none seem to give consistent result. Current example below that doesn't work.
var tempval = calcdistomove.Execute(ref currentBezier, 1.0f, placeonSpline.floatVal);
placeonSpline.floatVal = tempval;
var tempee = calcBezier.Execute(ref currentBezier, placeonSpline.floatVal);
moventity.Value = tempee;
Any help would be appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220613000616im_/https://answers.unity.com/themes/thub/images/avi.jpg)