I am currently having a FPS game with client side prediction. Every 20ms, the client sends it's input to the server. The server buffers 5 ticks worth of input (100ms) and starts consuming the inputs each tick and sends a world snapshot to the client. The client then validates the predictions and corrects the simulations if there is a misprediction. The setup works fine under ideal network conditions. However when the latency suddenly spikes from say 50ms to 400ms, the client's tick packet is delayed which causes the server to eat through all of the available inputs in the buffer and resort to using the previous tick values to perform server simulation. When the client input finally arrives at the server late, the server discards the input because it has already processed the input for that particular tick (using old input values).

How do I handle this edge case of latency increasing and decreasing? Sure I could use a larger buffer size for the inputs, but that will cause delays between client state and server state. Using a smaller buffer will cause the server to stall from inputs if there is a jitter that is more than the duration required by the server to process the inputs. I was under an impression that I would need some kind of dynamic buffer size that expands and contracts. However, I am out of ideas to implement something like this.

Does anyone have a solution?

  • \$\begingroup\$ Maintaining a buffer of past communication does not mean you need to delay handling it until the buffer is full. Many servers operate on a rewind system, where they can respond and relay each state change immediately. If a different instruction arrives later, they rewind to when it should have happened (within limits), and re-simulate from there, issuing corrections as needed. That lets you support a larger window for input without adding latency to everyone — you just need your interpolation to gracefully handle the correction when the official timeline changes visibly. \$\endgroup\$ – DMGregory Apr 28 at 10:48

Your Answer

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

Browse other questions tagged or ask your own question.