Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Multiplayer RTS General guidelines

Discussion in 'General Discussion' started by mkougiouris, Feb 27, 2014.

  1. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    Greetings all.
    I want to start creating an RTS game that will support multiplayer of up to 6-8 players per game.
    I have spent the last couple of days trying to figure out how to implement Lock-step as there are a variety of sources to give you the idea or to break into details, but there is no unity implemented example,and since i have never before got into networking this all seems a bit confusing to me.

    Now my question is, do i start creating the game by first setting up lock-step, or do i create the game as if it was singleplayer and i can implement lockstep at the end with minor or no change of the written code.i.e can i create the gui,unit/building scripts and player command ( select,attack,etc) first and then i can implement the lockstep at the end to synchronize multiple clients? Or do i need to implement the lock-step first?

    Also since we are using p2p and everyone is simulating the same world given that everyone knows every command and they execute at the same time.So in practice i would have every client run the same game code, but it will really be controlled by events (messages of the type (player1.action1) i.e a player drags and selects 20 units and click on somewhere for them to attack,then a message will be send to all other clients that the selected units are starting to attack a unit by passing arrays for example,and after everyone confirms they got the message then they all start simulating at the same frame rate?

    Also given that the lock-step mechanism was a must due to low bandwidth and low computing power of the time it was conceived would it still be necessary given today's computing power and bandwidth, apart from the security that it offers in terms of cheating?

    I mean is there a threshold to the amount of units that i can support without lockstep, for example is it a must for 1k+ units simulation, or would 1k units be supported otherwise?

    If someone has implemented lock-step i would love to hear how it is done,or how could i work around this in any other way.
    Thank you for your time all.
     
  2. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    I don't have the answers to your questions mkougiouris, but I just wanted to say that these are excellent questions! I am currently working on an RTS in Unity.

    I hope someone can answer most or all of these questions for you. Because they are exactly the same questions I have right now, and I'm about 60% of the way done with my RTS game (in terms of as far as single player can go).

    I really really really (I can't say really enough) want to be able to implement multiplayer for an RTS game, but Unity does not seem to make it easy at all, if it's even possible. So for all of that, I want to say, I hope someone can answer these questions.
     
  3. Garmalak

    Garmalak

    Joined:
    Aug 12, 2012
    Posts:
    113
    Don't make a multiplayer game. Make something simpler first.
     
  4. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    @Garmalak i have worked on other games a bit and i am confident i can do everything to create the rts, but i have no intention to create it as singleplayer,
    i.e i am only interested to make a multiplayer rts, no campaign ,no AI for opponents, only players, so not having to create the AI would compensate for the time i will spent on the lock step i believe.

    @Velo222 I want to make multiplayer only, medieval time rts, a.k.a melee ranged mounted and siege as a unit base,each consisting of 3-4 types.Resource based similar with AoE, basic gather-able resource economy,with "real world" mechanisms such as falnking, heigt advantage ( hills valleys etc.) and extended fortification options, as i want to emphasize on the siege-battle, hence why i have no intention to create a campaign or any AI at all (other than units behaviour i.e stance, patrol etc).Did i mention you wont be able to break stone walls with swords spears and bows? ^^ Anyway ill just keep on researching for the lockstep mechanism i guess, but can i take for granted that i can implement lock-step later on? I don't want to be in a situation where the game is almost finished but i end up finding out i need to readjust the whole code...
    What rts are you working on Velo?
     
  5. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    Lol. Pretty much exactly what you just described, except I'm planning on having single player campaigns, and vs. AI. I'm also probably not going to implement formations and maneuvers in my game. It would just be too much I think. My current game is a base building, resource collecting type of game. Think of like a cross between Warcraft 3 and Stronghold 3 in terms of mechanics :)

    I really wanted to make a medieval era rts game (and I'm doing it). Currently working on the AI.

    I also really would like to see someone answer the questions in your first post!


    Here's a screenshot from my game about a month ago:

    $In-game pic 2-1-2014 Reduced Size for Forums.png
     
    Last edited: Feb 27, 2014
  6. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    This is pretty nice.
    Did you create the models or do you have a designer? My weak point other than the lock-step is that i would have to use some dummy art until i find proper models,but cubes could work out aswell during the scripting i guess.
    How long have you been developing it?
     
  7. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172

    Absolutely, that's probably the best way to do it, is to use plain models/primitives (grey boxing or whatever they call it), just as placeholders while you actually program the game. I'm just terrible at doing that. I always seem to want to have something half-way believable to inspire me to program more.

    Most of my models/assets were created by other people. I've either had to purchase models off of the asset store (which is great btw), or pay a separate "contractor" 3D modeler to make a model for me (which is few and far between). Acquiring the assets is probably one of the hardest parts of my game right now - especially for an RTS. I'd love to have AAA quality models/animations, but it's just not financially feasible for me right now. But the ones I have right now aren't bad :) I really like how they're shaping out -- but would love to have better of course.

    I've been working on my game for over a year and half now, and I started 2 years ago with absolutely ZERO programming knowledge lol. I've been learning programming as I go, and if you count when I first touched Unity, it's been two years. I do the programming aspect of the game and I also have to design/create the GUI elements myself, as I am the only one working on my project. It's just a hobby right now, that I really enjoy learning with.

    I think you have to be a little bit crazy to try to make a full-fledged RTS game by yourself............ I'm not sure what that says about me :D
     
    Last edited: Feb 27, 2014
  8. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    I feel like I've hijacked your thread a little bit though. Someone answer the OP's questions up top plz. :)
     
  9. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    No its ok, i might get more help from you than i would by any other one.Ill keep in contact since you have already developed the game partially you could help me out with some things to get me started, ill send you a pm later on tonight,your info was more than valuable to me.

    And yes dummy art sucks, you can code everything but you dont get the visual reward for it once its done until you have proper models and animation, and i am rly bad at modeling. I tried once to make a human swordsman model...suffice it to say he ended up with no legs and an angel-like halo over his head....
     
  10. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    I have no intention of implementing lock-step in my rts, however im not following traditional rts in the sense that players will not be building bases/gathering resources.

    It will be a fully authoritative server running the entire simulation and updating the clients as required.
     
  11. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    @JamesLeeNZ yes but wouldnt that be a problem? lockstep is required mainly for troops/units that move and not so much for buildings etc. What will be your max amount of units? How many players are supported in each game? It could help if you could give your specifications and your solution, also have you figured out latency and package travel time estimation etc?

    If you are planning on low number of troops then i guess its ok but for say 500+ units how will communicate the data for so many troops in a way that wont effect gameplay?
     
  12. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    I only intend to support 5v5 with 5 vehicles per player.

    This means maximum 50 units at one time, however realistically, there will be a maximum of 30 vehicles in a scene at any one time due to unit destruction and time taken to build units.

    Supporting 500+ units will require a lot of cleverness in regards to updating only what needs it to minimise traffic. Like occlusion culling for networking.

    TBH, supporting 500 units without MP is a fairly technical challenge. You will have to break units down into clusters of units that are guided by a leader, so not every unit on the screen is its own entity.

    Keep in mind the game youre intending to create is going to take you years to finish. I would aim smaller. Ive been cutting features back in order to try and have a reasonable finish date. My game has been in development for over 2 years. Im sure I could finish it in a few weeks if I had the luxury of working on it full time.
     
  13. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    James,

    What would be your guesstimate then on the number of units that could be supported (for rts multiplayer) without using lock-step/determinism (for instance just sending the necessary game-state information)?

    Honestly I havn't even glanced at how to do multiplayer yet, so I have no clue whatsoever. But I really want to know if it's possible to implement multiplayer without the game being deterministic? For instance, I'd even be extremely satisfied if my game could support 1v1 multiplayer (with each player having say 150 units each), but I'd probably have to make it by sending a lot of game-state information I'm assuming, and NOT deterministic.

    And I'm only saying no determinism because I don't personally know how to make my game deterministic. But I havn't tried yet because I want to finish the single player aspect of my game first.
     
    Last edited: Feb 27, 2014
  14. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    I know uLink ran a 1000 player simulation. I didnt participate, and I dont recall the results, but I believe it was acceptable.

    Its a hard question to answer, because there's a lot more than just network processing to consider. I can get 500 vehicles cruising around trying to destroy each other (so thats AI, Nav, targetting, physics, 100s of projectiles/explosions/etc) with a reasonably high frame rate.

    I dont know enough about networking yet to give you anything concrete. I intend to get the game finished without networking first, otherwise it will never be complete, plus im intending on making the network version the paid version. I want to be sure there are enough people who want to play the game before I spend months implementing networking.
     
  15. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    Hmm, okay, I was just curious. But that sounds promising. I mean you did this with an addon like uLink and without your game being deterministic correct?
     
  16. mkougiouris

    mkougiouris

    Joined:
    Sep 29, 2013
    Posts:
    10
    i have been wating James answer on your question Velo for the last hour ^^ if you can support 1k units with the plugin this would be rly good news
     
  17. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    500 units was without networking. Its more of an indication on whether its possible to support 500 intelligent(ish) units.

    You cant do deterministic physics in Unity, so if you want physics based system, its gonna have to be authoritive and run the simulation on a server or another node if youre not concerned with cheating.
     
  18. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    Ah that's unfortunate. I guess I still don't know then :confused:

    I'm still not clear though on what "physics based" actually means. Because (I think) the only physics I absolutely need would be raycasting (for unit selection) and unit colliders for collisions. Any other physics would be purely for effect and not really required -- but maybe that is what you mean by physics based? I do use physics.raycast extensively.

    So, I guess I'm still questioning some things. What about peer to peer? If I do 1v1 networking, could one persons computer serve as an "authoritative" server, but still be peer to peer? Sorry, I'm still really unknowledgeable and new when it comes to networking, I'm not sure what the alternative to "authoritative" would be either.

    If I understand you correctly, you're saying an rts game that uses Unity's physics, and that is not deterministic, is possible, but you wouldn't have a good estimate on the number of units that would be feasible etc....?
     
  19. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,618
    Yeah I cant give a definitive answer on how many units Unity will support well with networking.

    Colliders and Collisions fall under the cant be determined bracket, unless physics are not being used to position the objects, which would have to mean that they are Kinematic rigidbodies.

    If you're moving your RB's via Translate, not only are you doing it wrong (unless they're kinematic), but you are also creating a non-deterministic environment anyway.

    The problem is, you cant guarantee that a collider will be in the same place on every machine every time. After a collision for example, if they are in slightly different places at the start of the collision, the result will be different, which has an on-going ripple effect.

    The thing I like about uLink is they run the simulation using unity physics on the server, and broadcast the positions, etc.

    If you want to use phsyics, there will always need to be a server, whether its p2p/dedicated it doesnt matter. One pc will have to do all the work.
     
  20. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    Right. Well that makes it a little more clear, thank you :) I'm still going to have to wait until I get to that "point" in my game development, and then hit the research hard for networking. I'm actually glad you mentioned you can make one persons computer the "server" in p2p. I think I might actually try to go that route. Thanks!
     
  21. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,832
    More Accurately: If you want to use a standard physics engine, then you'll need some sort of system to deal with floating point errors.

    ----

    @OP

    Don't worry about lockstep, and keep the game small and simple - *then* add features. As a random figure, keep the unit count below 100.
     
  22. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    For the OP

    If you want to implement lockstep, it needs to be done from the start as it affects everything in your game including buildings, your coordinate system and even if you're going to use floating points at all in your game logic layer.

    I would wager that nearly all lockstep Unity games (there are at least three published games, and one RTS library that does this) use integers instead of the normal floating point Transform component for logic.

    That said, if you keep it below 100 units, you can get away with an RTS that doesn't need lockstep at all. Just be aware that there is no converting to lockstep without rewriting all your game logic afterwards, unless C# or Unity provide a way to control floating point precision.
     
  23. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    I present to you Planetary Annihiliation:

    Feedback since alpha has been extremely positive regarding the stability, performance, and accuracy of PA's networking. That said, PA is using a custom engine - Unity is probably a bit too general-purpose to optimize for a massive-scale game like that. But it makes you wonder... is the lockstep model just a vestigial technique that isn't necessary anymore given the capabilities of modern computers?
     
    Last edited: Mar 2, 2014
  24. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,832
    I disagree - Unity provide very few to no limitations in regards to networking.
     
  25. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    I'll grant you that exception; I've always been curious about how they did it for PA. The last time I looked there was scant information on how they did their unit synchronization.

    There is very likely still a high level of determinism or simplification in their architecture, as their design goal of a million units in game is just something you can't haphazardly update over the network in realtime.
     
  26. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
    Finally found an article explaining it. PA tech is pretty cool, slightly different from basic client-server but it's definitely something Unity can support.
     
  27. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,832
    I have no idea how they actually did it (I am a backer, but haven't followed them). But I think a key is to ask what you actually need to sink.

    For example, take a huge RTS with 10 million units. Can you real time sync 10Mn units? Not easily. Can you sync 100 markers/units on the screen + a few data points for a mini-menu + 4 resources? Yep.

    Linky?
     
  28. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    I actually watched some of the PA dev teams stream last weekend, and they answered quite a few technical questions from viewers (some of the questions were directly from me :) ) .

    One of the interesting points John Mavor made (he's the director of Uber Entertainment I think), was that he said it is actually easier to "multi-thread the crap" out of the asynchronous networking technique they used for PA, than it is to multi-thread a deterministic/synchronous networking approach. I honestly have no idea about the details of why he said that, but he did.

    So he was kind of glad they used asynchronous networking for PA, and the game proves that it can be done for an RTS. The big question though, as cannon alluded to, is how much work it would require to be done with Unity. My guess is, it would take an enormous amount of time and effort to force Unity to do this properly for an RTS.

    But, again, I'm not an expert. I would love to hear from Cannon how this can be done in Unity, since he's claiming it can be.
     
  29. cannon

    cannon

    Joined:
    Jun 5, 2009
    Posts:
    751
  30. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    Great article. Thanks cannon.

    I'm still wondering how to actually "DO" it though. I mean, my networking experience is basically zero. He mentioned animations curves, but I'm still wondering how peope "network" animations. Do you have to send bone transform information every tick or couple of ticks in order to "network" animations?

    In any case, that article was really cool and very informative. Good find.
     
  31. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,832
    Typically you send little to no animation data. Many animations can be inferred by other information - e.g. walking/running animations can be inferred from movement speed, shooting animations from 'fire' events, damage animations from damage events /loss of hp.

    Even when we do start an animation, it's usually just 'start animation (xxx)' rather than syncing every bone every tick.

    Of course, different games have different needs and techniques to fill those needs.
     
  32. Velo222

    Velo222

    Joined:
    Apr 29, 2012
    Posts:
    1,172
    So you could have the client basically play a "running" animation based on when the server tells the client the unit's velocity is greater than 4.2 for example?

    Essentially, just having the client's computer run the animations -- but the animation state will be adjusted based on some other information such as velocity or a boolean that is set?
     
  33. npsf3000

    npsf3000

    Joined:
    Sep 19, 2010
    Posts:
    3,832
    Yep. That's how I've done it in the past (and IIRC many of the networking tutorials do this). A lot of animations are simply eye candy, and so don't have to be sent themselves. And as I mentioned, if you need to explicitly start an animation it's not hard.
     
  34. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,465
    Isn't there a way to batch animations in crowds with mecanim? I swear I remember something like that but haven't messed around with mecanim much.

    I haven't messed around with RTS, but in a day I had 5 players running around shooting lots of fireballs at each other, running through portals, and I was impressed by how synched it was, using photon. You don't send a ton of data, mainly position and rotation of things. The clients have all the animations/data and the network just relays positions/rotations and events to the clients.
     
  35. Mr_Perlful

    Mr_Perlful

    Joined:
    Dec 21, 2016
    Posts:
    6
    so i know this thread is ancient, but has anyone tried out using mqtt in unity for rts yet? if not i highly recommend attempting it.

    I had to write my own server and everything, mainly due to unique needs, but i wanted a light weight system to send messages to and from the server. since implementing into my current project im seeing faster load times, better client synchronization, less remote player lagginess and just all round smoother performance when doing some more cpu intensive work.

    i have an example broker and unity android/windows client im going to throw on github at some point. but if you like to nerd, mqtt should get you nice and hard. its cool when your game turns on lights and stuff in your house xD.