About FPS and dt
Posted: Mon Dec 23, 2013 4:28 pm
Hello everybody. I have some questions about FPS and dt not only on LOVE but on game programming on general.
If I want to move something on the screen and keep constant speed no matter what FPS the game is running on, I have to use something like this:
Here, if FPS is high dt tends to 0, so VEL*dt is low and tends to 0 (I have to move less on each frame).
On the contrary if FPS is low dt tends to 1, so VEL*dt tends to VEL (I move more on each frame compared to low FPS)
This works ok if I move things by myself. But if I need to apply force on a body in a physics simulation this doesn't work.
I figured out I needed to use:
If FPS is high, on each frame I apply more force. And if FPS is low I apply less force on each frame. This seems contradictory, but it works. And I don't know why!
I guess it's something related to the physics simulation, the friction of the body and other things.
Do you know why this is this way? I'm I doing something wrong? How do you manage these things?
If I want to move something on the screen and keep constant speed no matter what FPS the game is running on, I have to use something like this:
Code: Select all
x = x + VEL*dt;
On the contrary if FPS is low dt tends to 1, so VEL*dt tends to VEL (I move more on each frame compared to low FPS)
This works ok if I move things by myself. But if I need to apply force on a body in a physics simulation this doesn't work.
I figured out I needed to use:
Code: Select all
applyForce(VEL * (1-dt));
I guess it's something related to the physics simulation, the friction of the body and other things.
Do you know why this is this way? I'm I doing something wrong? How do you manage these things?