A game draws a picture, works out what has changed, draws the next picture and repeats. Each picture is a frame. Delta time is the amount of real time that passed between one frame and the next.
It is one of the first ideas a game programmer meets, because without it a game runs at different speeds on different computers. Its effects are also visible to players. Several well-known bugs come from games that got it wrong.
The problem it solves
Imagine a game that moves a character 5 pixels every frame.
| Frame rate | Movement per second |
|---|---|
| 30 frames per second | 150 pixels |
| 60 frames per second | 300 pixels |
| 144 frames per second | 720 pixels |
The same game is nearly five times faster on a quick computer than on a slow one. This happened for real. Many games from the 1980s were timed for the processors of their day and became unplayably fast on later machines, which is why some old PCs had a "turbo" button to slow the processor down.
The fix is to describe movement per second, not per frame, and to multiply by the time the last frame took.
distance this frame = speed per second x delta time
At 60 frames per second, delta time is about 0.0167 seconds. At 30 it is about 0.0333. A character moving at 300 pixels per second covers 5 pixels a frame in the first case and 10 in the second, and 300 pixels a second in both.
Where simple delta time breaks
Multiplying by delta time works for steady movement. It works less well for anything that accelerates, bounces or collides.
Different results at different frame rates. Physics worked out in large steps and in small steps gives slightly different answers. A jump can be a little higher at one frame rate than another. In a precise platformer, that can make a jump possible on one machine and impossible on another.
Tunnelling. If a frame takes a long time, a fast object moves a long way in one step and can pass straight through a thin wall, because it was never inside the wall on any frame that was checked.
The spiral. After a long pause, such as a stutter or a window being dragged, delta time is enormous. A game that trusts it moves everything by a huge amount at once. Most games cap delta time for this reason, which is why a game goes into slow motion during a bad stutter instead of teleporting you.
The fixed timestep
The standard answer is to separate the simulation from the drawing.
- The game's rules advance in steps of a fixed size, for example exactly 1/60 of a second.
- Each frame, the game adds the real time that passed to a running total.
- It runs as many fixed steps as the total holds: perhaps none, perhaps one, perhaps three.
- It draws the result, often blending between the last two steps so that motion looks smooth on a display of any refresh rate.
Because every step is the same size, the simulation gives the same result on every machine. This matters most for physics, for fighting games where every frame counts, and for online games where every player's computer must agree. A widely read article by the programmer Glenn Fiedler, called "Fix Your Timestep!", is the usual reference for the method.
Bugs you may have met
- Dark Souls II on PC ran at 60 frames per second where the console versions ran at 30. Weapon durability had been tied to the frame rate, so weapons wore out about twice as fast. It was fixed in a later patch.
- Bethesda's open-world games, including Skyrim and Fallout 4, were built around 60 frames per second. Running them much higher made the physics misbehave, with objects flying about and movement speeding up.
- Console games locked to 30 or 60 frames per second often have game logic that assumes that rate. This is one reason ports that unlock the frame rate take real work.
- Speedrunning is full of tricks that work only at certain frame rates, because movement or physics changes slightly with the size of the step.
- Fighting games avoid the whole problem by locking to 60 frames per second and slowing down, never skipping frames, if the machine cannot keep up.
What it means for you
- Slow motion is deliberate. When a game slows down instead of jumping ahead during a stutter, it is protecting its physics.
- A higher frame rate should mean smoother, not faster. If a game speeds up at a high frame rate, it is tied to the frame rate. Cap it at the rate it was designed for, usually 60.
- If physics goes wild on a fast monitor, cap the frame rate to 60 in the game or in your graphics driver settings.
- In old games, a frame limiter is often the fix for everything running too fast.
- Online games run their simulation at a fixed rate on the server whatever your frame rate is. A higher frame rate at your end gives you newer pictures and quicker input, not a different game.
- Browser games draw once per screen refresh, so one written without delta time runs faster on a 144 Hz display than on a 60 Hz one. If a browser game feels oddly fast on a high-refresh monitor, that is why, and setting the display to 60 Hz for that game is the workaround.
Delta time is invisible when it is done well. Every player on every machine sees the same jump, the same bullet speed and the same timing, and the only thing a faster computer buys is a smoother picture.