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

Networking with Farseer

Topics: Developer Forum
Apr 19, 2011 at 10:52 PM

Hey, I'm working on a game for PC and XBox360 that's using the Farseer engine for physics, and we're looking into adding networking into the game. I'm wondering if anyone has any advice as to the best way to keep everything synchronized between the different players? Each player controls a character, but there are also some physics objects in the world that need to be taken care of. Do I need to designate a "host" player, or can I have different players "responsible" for their own characters and sync them up? Thanks!

Apr 21, 2011 at 7:45 PM

It all depends on the type of server/client architecture you plan on using, but most likely you're going to end up doing a single server and many clients.  

I am in the middle of building such a system and so I can't say that this will work with Farseer, but I sure am going to try.  So here is what I'm doing...


I have a dedicated server that is the master of all clients.  It handles communication between the players, performs the game logic, and has final say on all values.  The clients themselves are mostly just simulations and input handlers.  The server continuously sends down data to update the clients so they stay in sync.

You could do the easy approach, which may or may not work depending on the complexity of your game...where the clients run their own simulators and then send up their positions (for example) to the server, and the server updates all the other clients.  Though this approach isn't recommended because the player could fake their positions or cause syncing issues where a slower player may see themselves in a different position than another player. Overall this won't work for most games.

The solution to that is much more complex unfortunately...and I hope it will work with farseer. But I am not beyond this point in my own implementation.   What I do plan on doing is to run the same physics simulation on the server and clients and than have the server update those clients occasionally to a definitive value so they all sync up correctly.  The major headache though is handling delay and say in the example of position, making sure the player's character doesn't get jerked around too badly.


The main concern I have, is if my server is bossing around the client, will farseer break down.  I know setting the positions directly can cause issues when the difference is great.  But if it's smaller (which I'm hoping mine will be), will it still work? I can only code it to find out.


This is a good document that I based my design from...I may have found it on this forum...I don't recall