Logic behind multiplayer physics

Started by
1 comment, last by Waterlimon 12 years, 11 months ago
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?

Cheers,
RumbleSushi
Advertisement
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.
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

o3o

This topic is closed to new replies.

Advertisement