How can I get the exact same physics results in a networked game?

Started by
6 comments, last by Guimo 17 years, 6 months ago
I'm trying to do something common: create a Scorched Earth/Worms clone (with multiplayer/networking support). I've been researching this for a while now and have even purchased several 2D engines (TGB, HGE, etc...), but I'm still really nowhere further than where I was when I started. The main problem is that apparantly physics will never perform the same way on different machines. If this was NOT the case, all I would need to do is tell each multiplayer client to spawn a projectile and I could rest assured that it will perform the exact same, but since this is not the case I need an alternative. One alternative seems to be using some kind of physics look-up table. This seems complicated and I don't understand this :( Is there a relatively easy way to create a multiplayer version of Scorched Earth/Worms and ensure that collisions happen the EXACT same way, etc, etc...?
Advertisement
calculate it on one machine, distribute the result to all others ?
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia

My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Having the server preform the physics is best solution. You could probably animate eye-candy on the client's machine, but calculate land deformation on the server.

If you want to duplicate the physics on each machine then you shouldn't have a problem. Just make sure you are stepping through the game with a preset interval, rather than basing it on FPS. If you use any random input then use the same seed.
kwackers is right. As long as you update at the same rate and use the same seed for random numbers it should be easy for the physics to match across machines.
Doing physics in one thread and rendering in another can help separate the two. That way you can step through the physics using a preset interval and step through the rendering based on FPS.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Quote:Original post by sofakng
The main problem is that apparantly physics will never perform the same way on different machines. If this was NOT the case, all I would need to do is tell each multiplayer client to spawn a projectile and I could rest assured that it will perform the exact same, but since this is not the case I need an alternative.


Go with a server-client model as davepermen and kwackers said. Basically, anything that's vital to the gameplay should be done on the server. Various games let the clients do some prediction, so everything looks smoothly between updates, but eventually, what the server says is what really happens.

Besides inconsistencies between players, there's another reason to go for this solution. It's because clients should not be trusted. What if a player had hacked his version of the game and used it to his advantage? It could ruin the fun for the other players, and that's exactly what you don't want to happen.
Create-ivity - a game development blog Mouseover for more information.
The catch to doing that much work on a server, is it can result in a fair bit of information having to be pushed over the wire. Another option is to have be server thats responsible for generation of all the input data and random seeds, and these are pushed over the wire. Each client then uses these inputs to calcuate physics locally which should result in an identical simulation on every machine.
I don't know if this may help you, but in Warscale I used a sync trick using my seeds.

Given that a random number generator outputs the same results given the same seed, then I sent ONE seed from server to clients. From that seed I got the 4 next random numbers. The 4 results were the same for all the computers in the network. Those numbers were used as a seed for 4 number generators, each one an independent object, each one used for different purposes, but the results were always the same in all the PCs as the seeds were the same.

A game like scorched earth only requires the same initial conditions (angle, power, wind speed, resistance). When you fire, the command is sent to the server:
FIRE|PLAYERID|ANGLE|POWER|WIND|etc etc...

The server replies to each PC and each one should get the same result.

This trick also works for multiplayers where a player can enter at any time. You should keep the seed and the number of times a random number has been generated. So when a player enters the game you can send that info and the new player knows how many number he must generate in order to be sync'd with the other players.

Luck!
Guimo

This topic is closed to new replies.

Advertisement