Client Side Prediction Example

So I have been having trouble getting Client Side Prediction (CSP) working in the game I’m currently doing. I decided to take a step back and create a simple program solely focused on CSP when I found this example: … /view.html

I went ahead and coded up a similar version of it in Panda3D for practice and to make sure I understood it.

Here’s the source and a self-contained zip.


The green pawn is the prediction, and the blue pawn is the last known position provided by the server. There’s a invisible ‘wall’ at x = 1 that the server knows of but the client doesn’t, so you’ll get to see the corrections if you cross it.

It doesn’t use any actual networking, but the idea is independent of it anyways (i.e. if you actually sent packets around instead of doing it without it, it would work)

Hopefully this is helpful to someone. I haven’t brought what I learned into my game yet, but it looks like I shouldn’t have too much of a problem.

it is a bit late ofa day for me to try your code. but have you seen pandas smoothmover? … hMover.php
it also has some prediction capability.

Looking at the thread here: [how to use SmoothMovers?) it sounds like the SmoothMover is used mostly for non-predicted entities (e.g. other players in the game aside from yourself). Have you accomplished input prediction before? The problem I’m running into as I try to get this to work in a game is that the client and server aren’t sync’d anymore - in my example, the time between frames is exactly the same for both the client and the server, where this is not the case for remote machines.

Aside from attempting to smooth out the times when the prediction doesn’t match the server’s location, does anyone have any ideas to make the prediction more perfect?

So I did some debugging and found out that the reason my prediction differs from the actual movement is out of order packets - so let’s say I send 3 move forward packets, but the most recent one arrives first. Currently, I’m discarding the old ones, which means that the server could move less than the client.

What if, instead of telling the server that the client is now pressing +FORWARD, I tell it I pressed +FORWARD for 5ms since the last packet I sent?

I figured it out. I wasn’t doing the exact same thing on both the client and the server (oops). This week is pretty busy for me, but I’ll try to get around to writing up a detailed explanation of what I did.