Question about the correct implementation of dt [SOLVED]

Good afternoon, I just now realized that there was no dt in my code.

{...}
self.pos.x = self.pos.x + (self.speed * speed_upgrade)
{...}

The speed was 1.0, the character moved as I wanted, but after adding dt, there was a situation in which in order to achieve the same movement speed I had to noticeably increase the speed value. (1.0 → 50.0)

The question is the following, do I understand correctly that when using dt you have to noticeably increase the character’s movement speed in the code and is there any way to avoid this ?

dt is the amount of time since the previous update - typically 1/60 of a second though it can be different depending on machine performance or monitor refresh rate.

If your speed was set to 1.0 before, set it to 60 and multiply by dt to get the same result.

4 Likes

To expand on that, multiplying the speed by dt means that it’s now measured in pixels/second instead of pixels/frame, so a speed of 1 pixel/frame becomes 1 pixel/second.

5 Likes