Is it necessary for everything? Why have I seen many tutorials that use this? :neutral:
What does delta time meant?
Delta time is the time it between rendered frames. You can use delta time to get frame rate independent behavior.
The reason you see so many tutorials is because it’s extremely useful. Without delta time you could have inconsistencies just by how fast the game is running. For example: If you move the character 5px
ever _process call, then you’ll move 150px (5px * 30fps = 150 pixels moved)
in one second in 30fps. However, if your computer is rendering at 60fps, then you’ll move 300px (5px * 60fps = 300 pixels moved)
instead, even though the code hasn’t changed at all. If your using 150px * delta time
, then no matter how many frames your computer is rendering at, it will always be 150px per second.
(Note: px = pixels, FPS = frames per second)
Here’s the wiki link, which (probably) explains it better than I did.
Thanks! Your explains clarifies the matters. And thanks for the wiki link
- Edited
Same applies to physics.
In _fixed_process(delta)
, the delta value is usually quite constant. If you use the default of 60 calls-per-second it therefore has the value of 1/60th seconds. Anyway it is also advisable to use the delta variable and not a constant value in this case because you can adjust your project to use another rate and then the code in all _fixed_process() functions will automatically adjust to that change when using delta.
An example for physics is if you want to continuously apply a force of "10" per second to some rigidbody. Then you'd apply an impulse of 10*delta
inside _fixed_process()
and these 60 times apply_impluse with 10*delta will sum up to a force of "10" per second. (Although the whole game states no units you can assume the unit for apply_impulse to be Newton metre or Joule if you assume m for position coordinates).