How to Use Delta

Complete Project

github.com/regakakobigman/Tutorial-Projects/tree/master/How to Use Delta

What Is Delta?

Delta (uppercase Δ, lowercase δ) stands for “change”, so it has many meanings. In game development, it’s used to keep the game’s physics consistent across different framerates. This is important for making sure that your players have a consistent experience.

Delta is really small. At 60 FPS, it’s close to 0.016. Your physics parameters (gravity, acceleration, etc.) will have to be very large to match; expect them to be between 500 and 5000.

Delta changes constantly. Specifically, delta measures the time that passed between the last _process / _physics_process call and the current one. It’s inversely proportional to the FPS, so if the FPS is 30, delta is 1/30 (or 0.03). The FPS can vary based on the player’s computer, the temperature, the number of apps they have open, the type of v-sync in use, and so on. Never rely on delta being the same value!

Delta allows for framerate independence. When you move a box 5 pixels to the right in _process , its horizontal position is increasing at a rate of 5px/frame. This is bad, because the box’s speed is tied to the framerate, so its behavior will change based on the framerate. Instead, you should move it (5 * delta) pixels to the right. This causes it to move at a rate of 5px/second. See what multiplying by delta does? It lets us change things over time using real time units, like seconds or minutes, instead of frames.

There are multiple ways to access delta. The _process and _physics_process functions give you delta as a parameter, so it’s always accessible inside those functions. If you split your physics code into multiple functions, you can give them an extra parameter and pass in delta when you call them. This will make delta available almost anywhere you need it.

It’s uncommon to need delta outside of _process and _physics_process , but if you need it somewhere else, you can use get_process_delta_time() and get_physics_process_delta_time() .

Just Enough Delta

There are places where you should use delta, and places where you shouldn’t. Most mistakes with delta are a result of thinking “that’s too much delta!” or “not enough delta!”, then adding or removing delta to taste. Unlike cooking, there is only one correct way to use delta in each situation, and it might take months to notice that it was used incorrectly. It’s a subtle flavoring that can make your physics inconsistent if you don’t balance it just right.

To help with this, here’s a list of common scenarios where you may need delta:

_process : This function runs once every frame. If you’re modifying a numeric value over time, you need to use delta here.

_physics_process : This function runs every physics frame, which, by default, always happens 60 times per second. Even if the game is running at a higher or lower framerate than this, _physics_process will always run 60 times per second, no matter what. You don’t need to use delta here (it won’t break anything if you choose not to), but you should still use delta anyway. If you use delta, you can change the physics FPS in the project settings later (e.g. to support 144hz monitors).

move_and_collide(velocity) : You need to do move_and_collide(velocity * delta) . This will make the distance you move framerate independent.

velocity = move_and_slide(velocity) : You don’t need to multiply by delta. move_and_slide will multiply by delta for you.

velocity += acceleration : You need to multiply by delta, like so: velocity += acceleration * delta . This might seem wrong, because the value added by acceleration is being multiplied by delta twice (i.e. velocity += acceleration * delta; move_and_collide(velocity * delta)) ), but this is actually correct. Multiplying acceleration by delta means your acceleration is framerate independent, and multiplying velocity by delta means the distance you move is framerate independent. One way to think about it is that when you multiply acceleration by delta once, it’s measured in units/second , and when you multiply twice, it’s measured in units/second/second , or units/second 2 , or… wait a second, that’s m/s 2 , the unit for acceleration! Does it make sense now?

enabled = true : No need to use delta here! If the value you’re changing isn’t numeric, there’s no need to use delta (since changing a boolean over time doesn’t really make sense). This also means checking for booleans like Input.is_action_pressed("move_right") is completely fine.

Living with Delta

Now that you know what delta is and how it works, you’re prepared for using delta in your own projects! It can be frustrating to work with, and you may wonder why it’s needed at all, but it serves a valuable purpose. It makes your physics consistent across different computers, so your players have a consistent experience.

To help illustrate the examples above, I made an example project for you to use; think of it like a delta lab. It runs in the editor, so as soon as you open the project, you can see it in action. Here’s a link to it.

Let me know if you have any questions about delta, the example project, or just have something to say. (twitter banner at the top, or message me: /u/regakakobigman)