Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

RTS style grouping

Discussion in 'General Discussion' started by smirlianos, Aug 30, 2014.

  1. smirlianos

    smirlianos

    Joined:
    Aug 2, 2012
    Posts:
    177
    I was playing Age Of Empires III recently and I questioned myself.
    What method do the developers use to move a lot of units at the same time?
    When you select a group of people and order them to move somewhere, they arrange their positions automaticly to a square.

    Example video:



    Any idea how this feature can be implemented with Unity?
     
  2. MrBrainMelter

    MrBrainMelter

    Joined:
    Aug 26, 2014
    Posts:
    233
    You can always ask Mr Granberg over at the AStar pathfinding project:
    http://arongranberg.com/astar/

    The answer to your question is quite complex. But his package contains an RVO avoidance algorithm that solves part of the problem, basically keeping units from moving too close to each other.


    As a side note, RTS in general is a very niche market. Starcraft makes up a huge share of it, and everyone else seems to get pushed out. So making a "traditional" RTS wouldn't be a very viable game idea.
     
  3. Myhijim

    Myhijim

    Joined:
    Jun 15, 2012
    Posts:
    1,148
    On a basic level you would be able to create a 'group like' movement method by parenting a invisible game object to the units. Then you would have to have an multidimensional array(obviously a 2D array in this instance because the y position is not as important) containing the units class or transforms, in this system you could have the physical transform positions (in local space the the parent) equal to the array position. Eg. Unit stored in the array at [1,1] would have a local position in relation to the parent of x=1, y=1.

    This array, with the input of the mouse would then update the parent's position and adjust every unit in the array's position to say :
    Code (CSharp):
    1. new Vector3(newPosition.x+arrayPosition.x,newPosition.y+arrayPosition.y,0)
    And then lerp to that position.

    The real beauty of this system is the pathfinding of the units and the ability to deform from a square when a unit cannot stand somewhere like over a body of water. That I don't really have a huge amount of time to theorize about.

    Of course this is all chucked together and is unlikely to work straight off the bat, this is just the method of approach I personally would take.
     
  4. smirlianos

    smirlianos

    Joined:
    Aug 2, 2012
    Posts:
    177
    I don't make it to have any profits! just for personal fun project!
     
    tonicalonzi likes this.
  5. MrBrainMelter

    MrBrainMelter

    Joined:
    Aug 26, 2014
    Posts:
    233
    In that case you should be all set. If you want to make a "traditional" RTS, it'll be a ton of work. But you can make something simpler, like a TD game or whatever in less time.

    More on your original question: the difficulty depends on how neatly you want them to move in formation. If you just want to send your units somewhere and have them just end up in formation, that's not too hard to do. But if you want them to maintain the formation through turns and stuff, then it gets tricky.
     
    Last edited: Aug 31, 2014
  6. smirlianos

    smirlianos

    Joined:
    Aug 2, 2012
    Posts:
    177
    I plan to have them end up in position. There is no need for maintaining it.

    Btw, do you know if it is possible with Unity free to have them pathfind their location on a changing enviroment? (I mean the terrain will change, as more buildings and stuff are going to be build, trees chopped down... etc)
     
  7. MrBrainMelter

    MrBrainMelter

    Joined:
    Aug 26, 2014
    Posts:
    233
    Afaik Unity free doesn't support pathfinding. The Granberg pathfinding project does support dynamic environments, but it might only be in the pro version ($100).