- Home /
RTS Multiplayer Model
Lately I've been trying to develop a RTS Multiplayer based game and I've read some stuff about how Age of empires multiplayer was done and some models of mutliplayer game and I'm quite worried if my model will work.
My idea was to have all the players host an instance of the game as client mode and the one hosting run two instances of the game, one as client like the others and one as server.
The server instance would receive all the commands or actions executed by the players and run the simulations (Like pathfinding, moving a unit, making a unit attack) and at the same time tell all the clients the coordinates (the state of the transform component) of all the units at all times, so basically only the server had the authority to move stuff around and the clients would only be able to see where the units are and select them to give them orders which are sent to the server and the server executes them.
At first I thought it would be a good model but then I realized it's very bandwidth consuming and I'm not sure if it would work. Since it's a RTS there could be 1000 units moving at the same time, meaning the server would be needing to send the position of 1000 the amount of clients connected (Maximum 8 players) and the corresponding action they are performing in order to predict the animation. So it would be 1000 Vector3s 8 times + a int of the action ID * 8, approx 32000 values per frame, meaning if server is running at 90 FPS we would have 2,880,000 values per second. Sounds like a great number to me but assuming we have a 1MBps minimum requirement bandwidth to play the game, would it be way too much data to be sent, or would it work?
Answer by MaxSmalls · Oct 02, 2014 at 05:11 AM
The technique used in most modern RTS is called Fixed Lock Step and sometimes Deterministic Lockstep. It's a bit harder to do in managed languages such as Mono/C# which Unity uses but can be done. Here's a link to a tutorial and sample set of code that someone already did in Unity: http://clintonbrennan.com/2013/12/lockstep-implementation-in-unity3d/
If you want a general overview of the history of networking models, this is a good place to start. http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
I also recommend the other information here too as it is relavent and gets pretty in depth on the problems associated with both networking and physics... or even worse trying to have networked deterministic physics!
Sorry I took so long to read your answer, but thank you so much! This was exactly what I was looking for, a website or someone explaining in depth how networking really works and the ways to accomplish it. I've seen the lock step tutorial already but I didn't really like the idea of how it works so me and my $$anonymous$$m decided to reuse our code and switch to a different type of game, but that's another story. And right now I'm reading the article about networking in games and it's super interesting, been looking for one like this but couldn't find, thanks so much again!
Answer by Kiwasi · Sep 23, 2014 at 07:43 PM
1 MBps strikes me as very high. You'll hit a GB of data in about 20 minutes. My entire monthly bandwidth would be gone after playing you game for 24 hours. (You may laugh, but capped internet is still a reality in many parts of the world.) Even on an unlimited plan my ISP provider would probably throttle speeds.
Ever wonder why Age of Empires had that annoying population limit?
Sending the position every frame is probably not needed for an RTS. You could send a current position and a target position a couple of times a second. Have the individual clients interpolate to figure out what happens in between.
Thanks for the answer!
Yeah I've though about what you said of somehow letting the clients run the simulation but not entirely, meaning the server will make them run small simulations every maybe 1 or 2 seconds so there's less probability of desyncing. And yeah age of empires (even AoE 2) can handle up to 1600 units per match, a very large amount but AoE uses lockstep networking which I kinda find annoying to code. It basically syncs every players game and runs game logic and simulations once per gameupdate ins$$anonymous$$d of once per frame, and it syncs the gameupdate across all the players and blah blah blah. It is a good system for networking but not exactly what I'm looking for since it seems like a pain to code everything in relation to that gameupdate.
Do you know of any other models or tutorials for networking on a RTS game?
Your answer
Follow this Question
Related Questions
Using Unity Navigation in a fixed timestep 1 Answer
Multiplayer RTS Script 2 Answers
Multiplayer RTS: Rendering a specific mesh for multiple cameras 0 Answers
Photon PUN 2 RTS one time information sharing 0 Answers
Unity networking tutorial? 6 Answers