Handmade Hero»Forums»Code
11 posts
Frame independence and gravity
How do you get gravity to work with frame independence? I multiply both gravity and jump speed with delta time and when fps change from 30 to 60 I get a 50% shorter jump, since jump vector gets exponentially shorter with gravity applied every frame, and at 60 fps you come out with half the length of a jump than at 30 fps, both taking the same amount of time.
How do you solve this?
Mārtiņš Možeiko
2559 posts / 2 projects
Frame independence and gravity
Edited by Mārtiņš Možeiko on
Day 43 covers this: https://asafgartner.github.io/annotations_player/hmh.html#day043#833

In simplest case you do :
Snext = Sprev + dt*Vprev + 0.5*dt*dt*A
Vnext = Vprev + dt*A

where S is position, V is velocity and A is acceleration (gravity in your case) constant/vector and dt is delta time between frames.
11 posts
Frame independence and gravity
Thanks a lot :)