Lag compensation is at the core of effective hit registration and fair gameplay for many online games. The best way to start with understanding lag compensation is to look at where it’s most commonly used: shooting an enemy player in a server-authoritative FPS game.

In an online game when you, the player, shoot another player there’s a good chance that according to the server and the other player you actually missed them. This happens because each player is ever so slightly out of sync with the other player, and both players are ever so slightly out of sync with the current server time. Without lag compensation, the server would simply look at whatever game state it has at the current time and decide whether or not the shot should hit. Often this would result in the shot missing, even when from the shooting player’s perspective it clearly hit. This is where lag compensation comes into play to solve the problem (as much as it can).

With lag compensation instead of simply looking at the current tick and checking if the player would hit or miss the server will instead go back to the the closest snapshot it has stored for when the player claimed they shot at, interpolate between stored snapshots to get an estimate of the game state at the exact time of the shot, and check if the shot would hit or miss if it was shot at that time. In practice this allows players with very bad ping to still have “good” hit registration. However, if the lag compensation is allowed to look too far back it can cause issues for the players getting shot at. To them it can appear as if they were shot through walls or barriers. This causes the phenomena commonly observed by players as bullets following them around corners.

Lag compensation also brings into play some network security concerns because it trusts players to tell the truth to the server about when they shot. Lenient lag compensation without adequate anti-cheat measures can open games up to cheats involving players intentionally misreporting firing times, allowing them to consistently kill players through cover even after they walked behind it.

One challenge with lag compensation is that it requires a substantial buffer of snapshots that it can quickly analyze. Lag compensation is often used in tandem with snapshot interpolation for this reason.

Lag compensation isn’t only used in FPS games. The same technique can be used pretty much anywhere where players might be out of sync and the server needs to see what they saw when they sent time-sensitive data. This can have its uses in games such as combat-oriented VR games, where good hit registration is especially important, or fighting games not using deterministic rollback, where moves hitting at the correct time is crucial.

Thanks for reading and hopefully this article helped you. Let me know in the comments if you have any questions or if there’s anything I can clarify on.