I have been following this guide http://gabrielgambetta.com/fpm1.html for my 2D platformer multiplayer game.

However I can't do client side prediction in my game. I'll try to make an example.

[Client Perspective] My game is locked at 60 fps, the client sends to the server every frame if some input has changed and records it. For example client sends to server that key left is pressed. Client moves the player every frame, (lets say velocity is 1) so during 30 frames the client moves the player 30 pixels to the left, 1 pixel per frame. Now at frame 30 client releases the left key, sends the input change to the server and player doesn't move anymore.

[Server Perspective] Meanwhile the server receives the first input change, now every frame server moves the client player 1 pixel to the left every frame. Later it receives the second input change, the key release. Client player doesn't move anymore. Server sends X position to the client.

Now the problem. Ignoring the fact that I need to determine the order of the received packets in the client and compare it with the input packets sent that have not yet been processed by the server, without even going into this. The server response will never match with my client prediction.


Because between the first packet (key press) and the second packet (key released) received by the server there may have been 25, 30, 40 or even 60 frames server side, because UDP packets are unreliable, so in the server the player may have moved 25, 30, 60, etc pixels... And in the client only 30. So when the server sends the player X position to the client it will never match with the clients X.

Someone can help me? Thank you in advance.

  • \$\begingroup\$ Would sending a frame index number with your key press packet fix your problem? \$\endgroup\$ – Harrichael Jan 18 '17 at 22:02
  • \$\begingroup\$ Already tried it and didn't seem to fix the problem \$\endgroup\$ – Alex Jan 19 '17 at 18:16
  • \$\begingroup\$ Do you trust your clients? \$\endgroup\$ – Steve Smith Jan 31 '18 at 13:51

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.