- Home /
Unity RTS Networking
So, I know this has been approached before, but I have a different take on this. I am currently making an RTS meant to have about 600 units max in the entire map.
Looking at the 1500 archers article on gamasutra, they synchronize the framerate and command-turn times to make sure that the deterministic approach they use will stay consistent. I have been browsing the Forums and Questions section, with little help on the why of this. A lot of people recommend using the article, but dont recommend an implementation or help with the implementation. Now, I have a (perhaps naive) question about whether or not something that doesnt follow the article would work.
I want to set up an authoritative server such that all gameobjects are created by the server and each unit has an owner that refers to who can command them. I do not want the system to be deterministic like the article suggests.
I want to synchronize the transform, state, and stats (hp, attk, def, speed - to prevent cheating) of the units from the server to the clients. Each client will send their commands in an RPC to the server, which should get executed immediately. Even with a little lag ~500ms between commands, the gameobjects will be synced from the server anyway, so when the server gets the command, the units should move on the client.
The synchronization will be done with NetworkViews using the RDC method, sending data around 10-14 times per second, depending on the performance I get out of it. Most of the stats dont change during the match, so they wont get sent to the other machines.
Would this system work, or am I overlooking something crucial? I think that as long as the Server runs the unit logic and is completely authoritative, then the clients will just "watch" results and send commands to the server to process.
Answer by D4rt · Jul 07, 2013 at 09:58 AM
600 units moving and shooting and doing all sorts of tomfoolery will result in a lot of data being sent to the clients. The P2P model commonly used in RTS games exists to minimize this network traffic I believe.
http://gamedevsoc.eusa.ed.ac.uk/2010/06/the-trials-tribulations-of-rts-networking/
Here is an easy read that explains a bit about RTS networking. Didn't read the whole thing but the first few chapters were solid. It also explains why the "one host" idea is bad.
EDIT: And about cheating. It shouldn't be an issue. You can do it like SC2 for example, where everyone connects to a server and the simulation is also run on the server. Thus the server can decide who wins even if someone cheats. This makes cheating "useless" as the player cheating only harms himself: he'll be the only one to see the "cheated" game state thus playing with false information.
I had seen this post before, but I missed the "Chapters" part of it. I wonder though, can Unity handle the lockstep model everyone is suggesting? I dont have control over synchronized frames, nor do I have control over the direct code sequence required to keep RTS games in sync. For example, if one unit is translated by .002, then it becomes in range of being targeted. He takes damage on one machine, but not another. How do I compensate for non-deter$$anonymous$$istic floating point calculations done in the transforms without having to rewrite all the physics?
I didnt select answer yet, because I want to see what other people think.
EDIT: Tone
Where there is will, there is a way. I'm sure that the model can be mostly implemented in Unity.
However the floating point problem is something with no easy solution as far as I know. $$anonymous$$aybe you could try to combine the models and do gradual updates that fix possible errors the clients have. This would mean that you lose most of the benefits of the deter$$anonymous$$istic approach though (and would probably be hellish to implement). Also the clients might wonder why a previously dead enemy suddenly spawns back to life inside their base.
Ofcourse there is the possiblity that Unity is not the optimal solution for a large scale RTS here. You can't be a master of all trades.
EDIT: http://answers.unity3d.com/questions/13264/is-a-unity-simulation-deter$$anonymous$$istic.html
This guy did it so it is possible. Not using the internal physics engine though.
So, Links to Links to Links from the one you sent me, link to this: http://gafferongames.com/networking-for-game-programmers/floating-point-deter$$anonymous$$ism/
However, now my issue becomes: Can I make Unity use IEEE754 standards. Thank you for your help D4rt