Lag compensation

Play this lesson

The firefly that moved

Shard Garden adds firefly catching. Kai taps a firefly exactly where the screen shows it.

But the screen shows the world about 100 ms in the past, and the tap takes time to reach the server. By then, on the server, the firefly has flown on. Without help, Kai misses a perfect tap.

Rewind

Valve's Source server "keeps a history of all recent player positions for one second". When a command arrives, it works out when the player saw the world:

Command Execution Time = Current Server Time - Packet Latency - Client View Interpolation

It moves the others back to that moment, checks the hit, then puts them back.

Quick check

What does lag compensation rewind?

  1. Other players' positions, to the moment the shooter saw them
  2. The shooter's own input
  3. The whole server clock
Show the answer

Other players' positions, to the moment the shooter saw them

Valve's server moves "all other players - only players - back", runs the command, then restores them.

The trade

The shooter's hits now match what they saw. The price is paid by the target: they can be hit a moment after reaching cover on their own screen.

Valve keeps just one second of history, so a player on a very slow connection cannot rewind further than that.

Do the sum

hit.log
server time: 10.000 spacket latency: 0.080 sview interpolation: 0.100 s

Kai's tap reaches the server. To which moment does it rewind?

  1. 9.820 s
  2. 9.900 s
  3. 10.180 s
Show the answer

9.820 s

10.000 minus 0.080 minus 0.100 is 9.820. That is when the shooter saw the target.

Only what moves

Walls, trees and plots do not move, so there is nothing to rewind. Source moves only players back, which keeps the check cheap.

For Shard Garden, the rewind covers fireflies, the one thing players race to catch.

Quick check

Source's lag compensation moves the whole world back in time, walls included.

Show the answer

False

Only players are moved back, then restored. Walls never moved, so they need no rewind.

Two players, every frame

Fighting games have a harder problem: two players, sixty frames a second, and every frame counts.

Bolt says: Next: rollback netcode.

Fact-checked 12 October 2026