I am implementing network rollbacker in real-time action game and found out a very strange issue where local (non-master) player is moved a bit forward then back when changing input.
After narrowing it down I found this is a source of the issue:
- Non-master player (let say at (0, 5) position) is moving forward via vector (1, 0)
- Player decides to stop moving. It immediately stop movement locally (as prediction) and then send message to server that it wants to stop
- As it is some time before the packet arrives, the server now thinks the player is at (1, 5) and it broadcast the information to all players
- The packet from non-master player arrives. Server immediately goes back a few frames and re-simulates (via rollbacker), and moves character back to position (0, 5). It broadcast the information again.
- The non-master player receives information that is should stand at (1, 5). It erroneously corrects its own position to (1, 5)
- The second packet arrives. The non-master player goes back to the valid (0, 5)
How can I correct the algorithm so the non-master player won't be doing this leap forward/back on changing input (5th and 6th step above), when receiving incorrect correction from master due to master not knowing its local change of input?