# How to use delta time when your speed needs to be always the same?

I am using Bezier curve, and that curve positions the entity when the step reaches 1, so anthing between 0 and 1 is his travelling distance.

So in my game, according to the speed I set, I want the entity move 0.01f steps towards the target, this means, the entity will reach the target position after 100 steps.

But if I will use delta time, this will change from time to time.

How can I use delta time correctly in this case?

I'm using libGDX.

The delta time is a measurement of time since the last frame and is best used when you want to change things based on time(and smooth across all platforms). So if you wanted your entity to move from the start of the curve to the end of the curve over 15 seconds you would increase the position by (deltaTime / 15) This makes the movement of the entity smooth even on platforms that are unable to keep the 60 fps frame rate.

If you used a static step value like 0.01f then on platforms that get 10 fps you will have an entity that takes 10 seconds to complete the curve. Whereas a platform that gets 60fps will have the entity in less than 2 seconds.

So, if you game requires the unit to compete the curve over the same amount of time you would use the deltaTime as a step value and if your game doesn't require the same performance across platforms you would just use a single static value like 0.01f.

Another option is to use a mixture of the two to limit the max step time so slower platforms aren't playing in slow motion. e.g.

if(deltaTime > 0.05f){ // frame took longer than expected
stepTime = 0.03f; // limit stepTime to 0.03f
}else{
stepTime = deltaTime; // deltaTime is within acceptable range
}

• Note the Bezier curve in the question will need some adjustments to the step, since a constant velocity input into a Bezier will generally lead to a varying output velocity. – DMGregory Sep 13 '17 at 12:26