← THE BLUE STICK

Guides / Game mechanics explained

What Is Delta Time? Why Frame Rate Changes Speed

PLAY NOWSolo, free, in your browser

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 rateMovement per second
30 frames per second150 pixels
60 frames per second300 pixels
144 frames per second720 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.

The same one-second movement at 30 and 60 frames per second Two rows showing a character crossing the same distance in one second. At 30 frames per second there are few large steps. At 60 frames per second there are twice as many steps of half the size. Both end at the same point. 30 frames per second: fewer, larger steps 60 frames per second: more, smaller steps same place after one second
With delta time, the frame rate changes how smooth the movement looks, not how far the character gets.

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.

  1. The game's rules advance in steps of a fixed size, for example exactly 1/60 of a second.
  2. Each frame, the game adds the real time that passed to a running total.
  3. It runs as many fixed steps as the total holds: perhaps none, perhaps one, perhaps three.
  4. 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

What it means for you

  1. Slow motion is deliberate. When a game slows down instead of jumping ahead during a stutter, it is protecting its physics.
  2. 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.
  3. If physics goes wild on a fast monitor, cap the frame rate to 60 in the game or in your graphics driver settings.
  4. In old games, a frame limiter is often the fix for everything running too fast.
  5. 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.
  6. 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.

PLAY NOWSolo, free, in your browser