Sign in to follow this  

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

This topic is 4094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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...?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

This topic is 4094 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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