Using delta time with addition and subtraction is easy.
player.speed += 100 * dt
However, multiplication and division complicate things a bit. For example, let's say I want the player to double his speed every second.
player.speed = player.speed * 2 * dt
I can't do this because it'll slow down the player (unless delta time is really high). Division is the same way, except it'll speed things way up.
How can I handle multiplication and division with delta time?
Edit: it looks like my question has confused everyone. I really just wanted to be able to implement deceleration without this horrible mass of code:
else
if speed > 0 then
speed = speed - 20 * dt
if speed < 0 then
speed = 0
end
end
if speed < 0 then
speed = speed + 20 * dt
if speed > 0 then
speed = 0
end
end
end
Because that's way bigger than it needs to be. So far a better solution seems to be:
speed = speed - speed * whatever_number * dt
No comments:
Post a Comment