So If I'm programming my physics/movement system using a fixed time step by doing everything in the _physics_process
function I can multiply an acceleration such as gravity by delta which will grant me an acceleration that reaches the desired position after 1 second of time.
In this case lets say I set gravity to 60
so that we travel 1/60 per "frame" (fixed time step). This will mean that after 1 second of time elapsed I will have traveled 60 pixels in total from the force of gravity. Because of the fixed time step we "know" that there will be 60 updates every second so it doesn't seem like we need to multiply the velocity also by delta.
var gravity = 60 # pixels per second
var y_velocity = 0
func _physics_process(delta):
y_velocity += gravity * delta
position.y += y_velocity
However I often see tutorials etc... mention that velocity also needs to be multiplied by delta to attain framerate independence/decoupling. Is this required if I have a fixed time step and am doing all of my calculations in _physics_process
? Or is this advice only for varying timesteps/for use in _process
?
position.y += y_velocity * delta
When I add a multiplication by delta to my velocity in the above example I get incredibly slow movement as the velocity has been made a fraction of what is previously was by being multiplied by delta. In addition to this, gravity
is no longer 60 pixels per second and is instead a tiny fraction of that, which seems like the "wrong" behaviour here logically, unless I'm thinking about this incorrectly.
To try to get close to the original behaviour we would have to feed in an incredibly large number for the gravity value, which seems "wrong" to me.
I was hoping I could get some advice/insight into what the best approach here would be. I get the feeling that I don't need to multiply y_velocity * delta
here after already multiplying the acceleration of gravity by delta and adding it to the velocity I think that the calculation with respect to the delta time has already been made and that adding it again is a mistake.
In the first example everything seems to behave as I expect but the second seems very off to me. Any help would be greatly appreciated here, I might just be missing something or misunderstanding one of the key logical aspects here.