Closed ArisKallergis closed 6 years ago
Could you point to the page your are referring to? The docs are big :)
I believe it should be explained that it works based on fixed frames per second, eg 60 fps.
That's actually not the case, unless you are in _fixed_process
, where the delta, i.e. the time elapsed between this frame and the previous one, would indeed be 1/fps
, so typically 0.0166667 s/frame. In _process
, delta will vary based on the actual computational effort of the past frame.
But yes, it could be made clearer to novice users that x += 20 * delta
is the same as the familiar distance = speed * time
in physics, i.e. increment x
by 20 px/s * the elapsed time (e.g. 0.3333 px if delta is 0.0166667 s/frame).
This where I felt like I needed a more detailed explanation: http://docs.godotengine.org/en/latest/learning/step_by_step/scripting_continued.html?highlight=delta
Thanks a lot for the fast response!
I have a question though. If in _process
the result is unpredictable still, what is the use? I 'm a bit confused. I thought the idea of delta is to give you a "target" to work with, actually in seconds. So that if i wanted something to happen every 2 seconds i would do something like delta/2
.
Thanks for the link, I'll check how to make things clearer.
The fact that delta
is not constant in _process
is not an issue for your use case, as the fractions of second will add up to 1 s too. See e.g. this unrealistic example, with x += 20 * delta
and an initial value of 0:
x = 0 + 20 * 0.20 = 4.0
x = 4.0 + 20 * 0.17 = 7.4
x = 7.4 + 20 * 0.22 = 11.8
x = 11.8 + 20 * 0.30 = 17.8
x = 17.8 + 20 * 0.19 = 21.6
So you won't reach the position 20 exactly after one second, but the speed is the same: 21.6 px in 1.08 s (0.20 + 0.17 + 0.22 + 0.30 + 0.19) is still exactly 20 px/s. So visually, your node moves 20 px/s, and that's all that really matters most of the time.
Thanks a lot. I believe the responses you gave me might be enough to make things clear more or less.
tl;dr Make the explanation more beginner friendly
I was reading through the docs and noticed that the delta variable is not (in my opinion) properly explained for someone uninitiated. I remember learning how delta works from the Unity3d docs, but because a long time had passed, i had forgotten what it was when reading the Godot docs. I believe it should be explained that it works based on fixed frames per second, eg 60 fps. As it is right now, it generally says something about calculating how much time has passed between two frames, and goes on to implement it. It doesn't for example let me know that if i write x+=20 * delta, it will move the character 20 pixels per second, which is vital to understand the concept in my opinion.