This week I focused on getting input prediction working. What I had working last week, I had the remote player pressing keys, sending them over to the server and waiting for the server to reply back with the next state of the player. Adding the 100ms delay for interpolation purposes you would have 100ms + ping time before you see your character move. That’s pretty bad as the game would feel very laggy.
What Input Prediction does is that the remote player’s avatar will appear moving immediately as if it’s a non-networked game. It will save the key strokes requests sent to the server by giving them an id together with the predicted position. The server will receive these key stroke requests, and will reply back with the resulting position as calculated by the server. The remote client will then receive these server-verified positions and double check if the positions calculated for that key stroke request matched or not. If it doesn’t match then it will start fixing the position according to what the server calculated.
The next part of the puzzle for next week is Lag Compensation. This will solve the issue for having events (like picking up loot or killing enemies) appear more responsive.