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?
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.
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 :
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.
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.
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)
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).