2
\$\begingroup\$

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?

\$\endgroup\$
  • \$\begingroup\$ You have a wrong assumption, 1 second of lag usually breaks the games, so they kick everyone above a certain threshold. \$\endgroup\$ – Bálint Mar 20 '17 at 7:57
  • \$\begingroup\$ ...and that's why fighting games were not the first to be multiplayer over the network. Timing is very important in these games, so when making these games to be playable over the network, you have to account for latency from the start... \$\endgroup\$ – Vaillancourt Mar 20 '17 at 12:21
  • \$\begingroup\$ as Bálint said, 1 second is huge. remember that ping is usually measured in ms, where 1000ms is 1 second, and depending on the game 200ms can be considered aweful and unplayable, fighting games tend to be in this category, 120ms probably already means a few frames of input lag to keep the experience smooth. \$\endgroup\$ – Brian H. Mar 20 '17 at 13:39
  • 1
    \$\begingroup\$ @repfarmer, while I appreciate a good Zalgo reference as much as anyone, I don't think the edits you've suggested to the title of this question are helpful. ;) \$\endgroup\$ – DMGregory May 28 '17 at 4:04
  • 1
    \$\begingroup\$ Indeed; please do not vandalize post content or titles. We want content to be readable and searchable so that future visitors can benefit. \$\endgroup\$ – Josh May 28 '17 at 15:09
5
\$\begingroup\$

The easiest solution to the "who did it first?" problem is an authoritative server. Both players connect to the server which handles all the game mechanics. Whatever arrives first at the server is considered as happening first.

So if the server receives a message "I place a wall" from player B and then a millisecond later a message "I move to where the wall is" from player A, the server will reject the move-message as impossible and send player A a corrected position for their character.

What then happens on the screen of player A is that their character moves at first, but then the wall appears and the character is snapped back to its position before the wall.

This method of resolving timing conflicts gives an advantage and a better game experience to those players who have a better connection to the server ("Low Ping Bastards").

A different way to resolve conflicts is to take latency into account when resolving actions. In order to do that, the server needs some way to keep a history of the game state. When the "I move to where the wall is" message arrives at the server, the server checks Player A's latency, looks into the history if a wall was already there a few milliseconds before, and decides accordingly. That means the game looks more consistent for high-pingers, but low-pingers will far more often witness situations where other players seem to walk through walls shortly after they were placed.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.