How do real-time multiplayer games deal with latency problems (or “server lag”)?
Imagine an online fighting game where 2 players battle head-to-head in real time. When a player performs an action, there'll be a short delay until that player's action appears on the opponent's computer screen. This delay causes many game-breaking problems.
Let's say 2 hypothetical players, Player A and Player B, are fighting against each other right now in the game, and the latency is 1 second. Player A is moving toward Player B, but then Player B places a wall (or something of the like) that stops Player A from moving toward Player B. Player A doesn’t see the wall appear on his/her computer screen until 1 second later, but by then Player A has already moved past where the wall was placed.
In a more game-breaking situation, Player B is just about to kill Player A. Right before that happens, Player A uses a special attack that instantly kills Player B. But on Player B’s computer, Player B kills Player A, because it takes 1 second before Player A’s special attack happens on Player B’s computer. This makes it so both players die even though only Player B was supposed to die.
One solution to deal with the latency issue is to implement an artificial delay so that when there’s a discrepancy, one player’s game is momentarily paused to wait for the other player’s game state to “catch up.” This is not a good solution because it makes the game feel extremely laggy and unresponsive, and it also renders some reactive actions useless (like dodging) because of the artificial delay.
What can be done to fix these latency problems?