I've been messing with the engine for quite some time, but I noticed I've been ignorant
to frame dependency till now. Most godot's demos have it, so I tried giving a look at it, but I still couldn't get it into my head. I even went through many articles, but it made me even more confused.
On my project, I move the player through a grid. Its a linear movement with a constant speed, so I do it like this :
#assign movement key
if Input.is_key_pressed(KEY_DOWN) && !moving:
total_movement = Vector3(0,0,2) #total transition
movement = Vector3(0,0,2) #current transition
moving = true #start walking loop
move(total_movement/32) #move by fraction
movement -= total_movement/32 #consume fraction from current transition
#if movement has been fully consumed, closes walking loop
if movement = Vector3(0,0,0):
moving = false
Although the code above is really rough, it is good enough to not leave any problems.
The player moves 0.0625 each frame, which is also subtracted from "movement", that will become a perfect 'Vector3(0,0,0)' eventually, sinalizing the end of the cycle.
But this is a bad practice as it seems, meaning players with lower FPS will see the unit
walking at lower speeds and players with higher FPS will get higher speeds.
From what I understood, there two ways of making games framerate independents so FPS don't determine physics actions:
Adapting all physics interactions to multiply by delta as an
damage control switch
Fixing the Timestep
So following the first step, I went to integrate delta into all my loops, and as I got a good result, it didn't last long. As more extreme FPS variations appeared, they broke the values and skipped conditions. So I had to create more functions and implement more equations to adapt my code to these variations, until I bloated the code, gave up and reverted it back.
Then I went on about the second step, that is almost spammed at every related question I found, but I really didn't get it at all. It's about decoupling the render from the physics and syncing it up in code. Couldn't get the pseudo code neither other users versions. It seems that everybody read the same article and somehow got a different concept from it while explaining.
So I was wondering if someone with a good grasp on the subject could get an example in GD or some advice on what take I should use on the subject.
Any help is appreciated, thx!
When should I use a fixed or variable time step?
motion calculations in games
Fix Your Timestep!