Kolton Ndoj

Game physics engines: faking Newton 60 times a second

Every time a ball bounces, a car crashes or a ragdoll flops in a video game

What problem does it solve?

How does a game make objects move and collide realistically in real time?

The big idea

The game can't solve Newton's equations exactly, so it takes tiny time steps: from the forces, nudge the velocity; from the velocity, nudge the position; repeat. The order matters a lot. Update velocity first, then position with the new velocity ('semi-implicit Euler'), and orbits stay stable; do it the naive way round and planets slowly spiral outward, gaining energy from nowhere. Collisions are handled by detecting overlaps and pushing objects apart with an impulse, a sudden kick that bounces them off.

How it works, step by step

  1. 1. Add up the forces on each object (gravity, springs, thrust) to get its acceleration a = F/m.
  2. 2. Update velocity: v ← v + a·Δt.
  3. 3. Update position: x ← x + v·Δt.
  4. 4. Find pairs of objects that overlap, push them apart, and apply bounce impulses.
  5. 5. Draw the frame, then repeat with a fixed Δt (e.g. 1/50 or 1/60 s).

The key formula

vk+1=vk+ak Δt,xk+1=xk+vk+1 Δtv_{k+1}=v_k+a_k\,\Delta t,\qquad x_{k+1}=x_k+v_{k+1}\,\Delta t
Δt\Delta t
the tiny time step between physics updates
aka_k
acceleration from the forces right now (Newton: a = F/m)
vk+1v_{k+1}
using the new velocity to move is what keeps orbits from spiralling outward

How fast is it?

Moving objects is cheap; collisions are the expensive part, because checking every pair of n objects costs about n²/2 tests. Engines first sort objects into grids or bounding-box trees so they only test objects that are near each other.

Try it yourself

Fun fact

Unity's physics runs by default at a fixed step of 0.02 seconds (50 times a second), separate from how fast frames are drawn. Speedrunners exploit physics glitches like 'clipping' through walls, many of which come from these tiny time steps.

Related

Open it in the Math Lab →

Games · Intermediate