+1 vote

I see on some examples and demos (like the Kinematic Character one) that delta is used when calculating movement and such. But in another one (the Platformer demo), delta is not used (or at least I didn't find it).

What is delta used for? I've made my characters move without using delta in the calculations, is that a bad thing? Is it always necessary?

in Engine by (93 points)

2 Answers

+5 votes
Best answer

Delta is the amount of time elapsed from the last frame draw to the present. Since fps go up and down constantly (unless you have a monster PC), using it allows to keep the exectuion in sync with the video.

Not using delta in a big game, could cause the same strange behavior in several parts of the game that you can see when your internet lags in an online game. That is, your fps could drop to about 5fps, but calculations are still going on at the same speed, and you suddenly see characters teleporting, or you die before even having time to react.

So briefly, delta is used to slow down the code execution to match the screen update rate. Use it always. :D

by (372 points)
selected by

I see, I'll use it now! Thank you very much!

+2 votes

I can simplify the explanation with an example.
Suppose an enemy is coming at us with a speed of 10, means it moves 10 pixels per second. If he hit the hero, it is game over.

Condition 1 without delta:
* If a user has the same fps as ours, he will play as we want.
* If a user has half fps, the enemy speed will be half of the original speed.
* If a user has a super computer and double fps, he may not be able to play the game because the enemy will reach him at once.

Condition 2 with delta:
The speed is multiplied by delta.
* If a user has the same fps as ours, let's say 60, the delta will be 1/fps = 1/60 =0.016
His speed will be 10x0.016 = 0.16 per second
* If the user has half fps, that is 30, the delta will be 10x1/30 = 0.33 per two seconds. Because his fps is half the speed appears exactly as for the 60fps guy.
* If the user has double fps, that is 120, the delta will be 10x1/120 = 0.08 per half second.
Because his fps is double, he will update quicker than the 60fps guy the speed appears exactly as the 60fps guy.

So whatever the fps, the game entity speed will be the same.

by (750 points)

how it can be
10 x 1/30 = 0.33 per two seconds
10 x 1/120 = 0.08 per half seconds

why not
10 x 1/30 = 0.33 per seconds
10 x1/120 = 0.08 per seconds

looks like its something simple but there's still a little im not understand

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.