This project has moved and is read-only. For the latest updates, please go here.

Destructible terrain and network play.

Topics: Developer Forum, User Forum
Sep 1, 2011 at 9:46 PM


I'm planning to build a side scrolling 2D shooter where you go head to head against to other people over the network.

If it was just about syncing a few physics object I doubt I would have any trouble but my main goal is to have destructible terrain in the game, and figuring out how im going to keep that in sync with current and joining players is giving me a bit of a headacke.


My first though was to try to keep all destruction of terrain in circles, ie all explosions are exact circles, that way i can send a position and a radius to all clients, which seems easy enough... But as the game progresses there is a risk (more like certainty) of these packets being dropped at some point. So i need to be able to check if the player has a correct version of the ground, and if they dont I need to be able to send them an updated version of the map.

However, the map is a minimum of 10000x5000 (= 50000000 pixels) and to send the entire map as a mask ( ie 1 or 0 for each position depending on if it has ground in it or not) would use quite a bit of bandwidth.

Then theres also the problem of someone joining half way through the game, and while they are receiving those 50000000 pixels the whole map could in theory have been changed before he is ready to play

How would you guys solve this.

Sep 1, 2011 at 9:58 PM

Every event increment a "Map Version #" and send it out with all the other data. Each client can check this number to see if they are current with all the events. Or something like that.

Sep 1, 2011 at 11:00 PM

Or you have a VEEEEERY big display or you won't be showing all the pixels all the time, so I suggets that the server only sends the part of the file where you are, like it's done in Minecraft, Terraria, Google Maps, or many other games with big worlds.

Sep 2, 2011 at 3:37 PM

Structure it as a list of circle deformations.  Each time there's a new one, add it to the list.  Then, on the server, maintain a number representing the last index the player was notified about.  Each time you're ready to update the player, send them a subset of the list with a LINQ query like, from circle in caCircles where caCircles.IndexOf(circle) > player.lastIndex AND circle.Position.InRange(player.Position) select circle;  A player joining the map would have an index of 0, and would receive all circles.  A player that lagged and missed several updates would get all the required circles.  Then, the client->server protocol could have something like "missed1" and "missedmany" messages to say "I got everything except for number 35" or "All updates since number 47 got dropped".

Sep 2, 2011 at 7:08 PM

Since shooters are generally action packed, you're not going to have time as a luxury and thus you'll have to be smart about how you send the map data to the client.  Sending the whole map wouldn't work in this case, that's far too much data.  Quantum's suggestion sounds workable.  You may also want to look into writing a routine to handle missed messages so you can ensure that the player didn't miss any updates.  I'm sure there will be other instances where you'll want that functionality not related to just destructible terrain.  If you haven't seen it, Lidgren Networking is a good c# networking library.


I've also been working on the side on a 2d shooter with farseer.  Though I haven't been able to work on it for awhile, I have spent a great deal of time trying to get basic multiplayer working with networked physics.  I haven't given up yet, but I've found it very difficult to sync the clients up and stop jitter even with various smoothing and prediction.  In general the clients are pretty close, but there is still the occasional obvious fighting between the client physics and the server physics.  I was curious if you've been able to get that working nicely on your end? Just basic character movement that looks synched up and smooth on all clients.

I'd like to know mostly to give me the peace of mind that it can be done.  I've read that some people have done multiplayer farseer physics, but those game didn't look like they needed as much precision as a 2d shooter.