Rollback Netcode, Explained
The speed of light is not as fast as we would like.
When players are far away from each other, there is a delay between when the player sends an action and when another receives it. This delay is called latency, and it can make games feel unresponsive. Imagine pressing the jump button and your character not jumping immediately. Rollback netcode is a technique that makes a game feel responsive even when players are far apart.
What is rollback netcode?
Normally, a game would have to wait for all inputs to arrive before simulating a frame. The waiting time is what causes the latency. You press jump, but you can't see the result because your computer is still waiting for your opponent's inputs to arrive.
Rollback netcode allows your game to move forward without waiting. The game predicts what the missing inputs are likely to be, then simulates the next frame using those predicted inputs. This lets it move forward. If later the actual inputs arrive and they differ from the predicted inputs, the game rolls back to the point in time where the prediction was made, and then re-simulates the game from that point forward using the actual inputs, correcting any misprediction errors.
There may be a little blip when the game corrects itself, but it can be smoothed over using rubberbanding and normally the correction is so small and quick that the player does not even notice it.
Rollback netcode lets the game appear to respond immediately to player inputs, even when there is significant latency between players. It is commonly used in fast-paced player-vs-player multiplayer games where the milliseconds matter.
Why does rollback netcode work?
Generally players only provide input a few times a second, while the game is simulated 60 ticks per second, and so most frames can be predicted accurately without needing to wait for all inputs to arrive. That is why rollback netcode is able to hide latency so well in practice.