🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Need help with client side replication...

Started by
1 comment, last by hplus0603 4 years, 9 months ago

I developed a pretty basic system for client side replication, but it doesn't work well enough at all.

Basically, the game I am making has multiple users, and the level contains geometry such as boxes that need to be in the same position and orientation for each player. The players can interact and push around the boxes as well. This makes client side prediction necessary, as I can't simply replicate the transforms or player input will be delayed when pushing the boxes.

Pushing boxes around smoothy with 150 ping is my goal.

Now let me tell you about the system I have. Imagine a level with a box in it. The client stores the position, rotation, velocity, angular velocity and world time of that box every tick into an array. This is a history of information for the object. The server sends the same information across the network frequently (for testing, as frequently as possible). This information takes time to arrive on client (150ms for testing) so the client looks 150ms into the past in order to find out his values at the same time as the server's values. The client calculates the difference between what his velocity was and what the server's velocity is, and adds that to his velocity (the difference is multiplied by a factor that I can modify). On top of that, the difference between positions is multiplied by a different factor and added to the velocity. 

There is no need to worry about angular velocity just yet. With the current system, I get sloppy results. Is there anyone out there that understands client side prediction enough to help me? 

 

Thanks. 

Advertisement

Your correction system is effectively a "PID" controller with a "P" term. These will always be "springy."

There are two things to do to make it better.

First, make sure that the very simplest case with zero loss results in zero correction. Make it so that the player pushes the box at time T with some known velocity, but doesn't push at times T-1 or T+1. Then make sure that this action can make it through the system without correction. If you get corrections, it means either that your communication system corrupts data, or that the time stamps aren't correctly used. (That is: The player needs to push the box "ahead" of the server to arrive in time.)

Once that works, you have to make a trade-off between "degree of acceptable difference" versus "degree of snappiness in corrections" versus "degree of sloppiness in movement." There is no 100% correct solution here. If nobody else has pushed the block in the intermediate time, you might even choose to let the client's position be preferred, and correct the server (within reason.)

I would nominally assume that a reasonable system would correct the velocity by exactly the difference, and correct the position by exactly the difference, for each step where there is a difference, but then subtract out that difference until you reach the step you corrected at.

E g, if you correct based on a delta at time (t-15) by dV and dP, then you should remove dV and dP from the calculated corrections for times (t-14) ... (t-1) but should then assume that you're in sync again at (t+0). This means that you need a second array, into which you accumulate correction turns, so you know not to re-correct for the (t-14) discrepancy if you already corrected for the (t-15) one.

enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement