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. Add up the forces on each object (gravity, springs, thrust) to get its acceleration a = F/m.
- 2. Update velocity: v ← v + a·Δt.
- 3. Update position: x ← x + v·Δt.
- 4. Find pairs of objects that overlap, push them apart, and apply bounce impulses.
- 5. Draw the frame, then repeat with a fixed Δt (e.g. 1/50 or 1/60 s).
The key formula
- the tiny time step between physics updates
- acceleration from the forces right now (Newton: a = F/m)
- 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
- Make Δt huge in the demo. What breaks first: orbits or collisions?
- Why can a fast bullet pass straight through a thin wall in some games? (Hint: between two frames it's never overlapping the wall.)
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.