Gravity Delta Time
This Demo is not designed to run on your device. Add it to a collection to play later, or you can try to run it anyway.
Explanation video on youtube!
The right way to apply gravity with delta time is not obvious. There are three basic ways to do it:
- before movement
- after movement
- half before and half after movement
Only type 3 is correct. Type 1 makes the jump arc get smaller at lower framerates, and type 2 makes the jump arc get bigger at lower framerates. This looping example demonstrates this fact.
Code:
func physics_early(delta): #wrong
# ... inputs, jumping, interactions, etc. go here ...
velocity.y += gravity*delta
global_position += velocity*delta
func physics_late(delta): #wrong
# ... inputs, jumping, interactions, etc. go here ...
global_position += velocity*delta
velocity.y += gravity*delta
func physics_mixed(delta): #correct
# ... inputs, jumping, interactions, etc. go here ...
velocity.y += gravity*delta*0.5
global_position += velocity*delta
velocity.y += gravity*delta*0.5

Comments
Log in with itch.io to leave a comment.
This is huge aha moment! 👍