what is rollback in fighting games and how come it makes it feel like there isn’t really any lag?


what is rollback in fighting games and how come it makes it feel like there isn’t really any lag?

In: Technology

When you play online it takes time for control inputs to get from player A to player B and vice versa. In a rollback scenario, player B’s computer is constantly trying to predict what input it will receive from player A and animates the game based on the predicted inputs. When correct, it appears lagless. When incorrect, the game basically skips a small amount to correct the mistake.

So for example:

Payer A presses X (punch) at time 0.00s

Player B’s computer predicts player A pressed Y (kick) at time 0.00s. So now player B’s computer starts to animate a kick.

At time 0.1s B receives the command player A pressed X at time 0.00. Player B’s computer “rolls back” the game 0.1 seconds, works out what would have happened if a punch was thrown over those 0.1 seconds, and then skips forward again to adjust the game for the actual input. From player B’s point of view, half way through a kick, it changed to a punch. However player B was able to press block, which is equally valid on a punch or a kick, so in this case the incorrect cue from the prediction algorithm was still helpful.

When lag is low (say 30ms) this isn’t noticeable, but when high, the quality of the predictions becomes important and artefacts like teleportation become apparent.

To further improve things some games include a small amount of input lag, say 20ms. This lag is always there, and it’s always constant so you’re used to it. This 20ms input lag gives the game a little window for the game to “catch up” in during a rollback event.

There are two ways you can write up the netcode for a game. You can either handle the button presses when they were originally pressed, or you can handle them when they get to the central server.

Let’s say you’re starting with the central server timing. This is also referred to as Delay-Based. If you press a button on your screen, until you receive an acknowledgement from the server that the button was pressed, nothing happens. This creates a lag that you have to overcome that just isn’t present with in-person gaming, and is going to vary greatly depending on your connection at the time. However, everything you see on your screen is guaranteed to be what actually happens.

The other way, handling buttons based on when they were originally pushed, is what is referred to as rollback.

Imagine each button press gets sent to the server with a timestamp. Your local game can start playing the actions right away, because it expects that the server will accept that button press at that time.

When it gets to the server, it will look at the timestamp of the button press. If it has already done any calculations for any button presses later than that, then it rolls back those button presses, adds the new one, and then replays them, and sends the correction to both clients.

This means that you effectively always get your button press at the time you pressed it, without weird lag making it much later than you intended. This also means that, if there is substantial lag, you can see the game stutter as it corrects itself, but if there is very little lag, then everything appears very smooth for both players, making them feel as if it’s a local game.