Sign in to follow this  

Logic behind multiplayer physics

Recommended Posts

rumblesushi    159
I'm possibly going to add multiplayer to my first game, and I'd like to know the general theory behind it.

Obviously even in local multiplayer, you have ONE physics engine handling collisions between players, no different to player vs CPU collisions.

But what about online multiplayer? There you have 2 physics engine running simultaneously, how exactly is the collision handled?

One idea would be to share the computations between them, but surely that's actually a bad idea, as it means more network traffic when colliding.

So possibly the cleanest most efficient solution would be to determine which user's machine is performing better, whichever has the lowest time step between frames, and calculate the collisions only on that one machine, and exchange positions etc as per normal. Obviously this wouldn't apply to consoles, as the users would be on identical machines, but on PC's the logic seems OK.

How is it generally handled?


Share this post

Link to post
Share on other sites
Dunge    405
Most games have a client/server logic meaning one people host the game, and another (or multiple) peoples join the server. From what I know, the server have the real objects physic positions and force them to all clients once in a while (avoid hacking), but the clients can use prediction on their hand using their physic engine to interpolate positions smoothly between server refresh (only visually). Of course it's probably much more complex and handled completely differently on multiple commercial game engines.

Share this post

Link to post
Share on other sites
Waterlimon    4398
You could for example make the server calculate physics for the objects and the players, and have the client calculate physics for the player and nearby objects (to make it look accurate)

If there is an error between the client side and server side objects, the server side data is used to fix their position and velocity, but for characters, the client side information should be used (if the error is small, and it should also be checked to make sure that you cant cheat by always telling the server that it needs to move the player forward a bit every update...)

You dont even need to do much server->client physics updates if the simulations dont have much errors.

You could lets say only update parts that the player has touched recently with a higher rate because the character is at different position on the client and server, and thus causing errors to the simulation...

Though if the client machine is laggy and cant proparly compute the nearby parts to make the physics look smooth you propably have to update more often :P

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this