RTS Multiplayer Networking

Hello,

I know this is a topic that has been brought up numerous times. I have spent the last 6 or so hours googling, and I’ve looked at every thread in the forum, every question/answer in the Answers section, and I haven’t found anything that can help me get started. I’ve found some useful bits of very general information, like lockstep etc, but Im not sure where to actually start.

Here are my goals and requirements:

  1. A competitive, eSport-caliber game with extremely low latency, possible regionally limited to ensure good connections.

  2. A small-scale, tactical 1v1 game with at MOST 30-40 units per player (though typically around 6-10 units).

  3. Authoritative server is not an option. I can’t accept the latency hit that results from it, nor can I afford it or scale it. It HAS to be peer-to-peer. I will have a server included at some point, just to check for disconnects and possibly to check for cheaters trying to edit game vars like unit costs and build times, but that’s all it will do.

  4. Ideally it will be true peer-to-peer and fully distributed, so that if I do support 2v2, the “host” doesn’t kill the game if they leave - it just keeps running.

  5. I am ok with everyone slowing down to the speed of the slowest connection. Eventually I will have a matchmaking server that prioritizes good connections, so it will mitigate that problem.

  6. I will not be doing any rigidbody physics simulations in the game at all. It will all be procedural, with various prefab animations and explicit transform-to-transform targeting. Though I don’t know if things like sphere colliders and Raycasts count as physics (e.g. use imprecise floating point math).

  7. I don’t plan on implementing replays right away. Replays are useful but streaming and commentary has taken over as the primary means to watch a match, so replay functionality isn’t a huge requirement. Thus I don’t technically need a fully deterministic simulation. My goal is just to get a playable game, and if it works, I’m fully willing to re-code it from scratch to support replays, if necessary.

What I don’t know is where to start. Is it possible to do deterministic lockstep in Unity, in case I wanted to? Can I make it semi-deterministic? If that’s not possible, given my very small unit counts, is it possible to just send full game state data between clients every 100ms or so to always ensure they’re fully synced? Can someone give me an example of how I would separate simulation logic frame rate from visual frame rate? How do I count “ticks” and keep them in sync between players?

I’ve searched high and low and I just can’t find a tutorial that sets the foundation for this type of networking in Unity.

Any help would be MUCH appreciated.

The reason there is no tutorial for building something like this is that it’s an incredibly complicated problem, which most often ends up being game-specific and is not easily abstracted out into a “tutorial”.

On the topic of deterministic simulations in Unity, yes it is possible - but, you will not get any help from Unity as I don’t think any of the existing systems (physics, animation, etc.) are deterministic and you would need to roll your own stuff - that means implementing everything from yourself, ground up.

Not sure what you mean by “semi-deterministic”. Also sending full game state in a peer-to-peer game is usually out of the question, especially with a game with many moving parts (units, abilities, etc.).

How to de-couple simulation from rendering, that is exactly what FixedUpdate (simulation) and Update (rendering) does.

Take a look at this article from age of empires developers, www.gamasutra.com/…/3094/1500archers_on_a_288_network.php Fholm is right about deterministic simulations and unity. Basically you better off with integers instead of floating point numbers if you can and for doing lock step you can use FixedUpdate or any other method which executes a method after a predetermined time,

How would I use integers to handle things like transform positions and rotations?

fholm told you right here :slight_smile: You will need to make your own math library. And, just a note for you, don’t use the unity random, use system.random.

Or you can find a good .NET math library on the net. There are quite a few, including one that fholm is using in his slim net

Yes but neither of them are gurantueed to be fully deterministic across all platforms and architectures.

Ya know fholm… if you made a math lib for unity, I would buy it :slight_smile: And honestly, I think there would be demand for a networking lockstep system!

Already have the FPS kit in the works, been fiddling on it on and off for a 6 months now ;p

Did you end up doing the FPS kit in lockstep?! You are much more motivated than I am… lol