Unit Formations

Hello guys,

For my RTS game I am using A* and a number of steering behaviors to manage my unit movement.
However there is 1 thing that keeps bugging me.

Whenever ordering a group of units to a certain location, they all compete for that single spot because it is their destination.

I solved this problem by detecting when the unit that is ahead of you, has arrived at it’s destiation. If so, then order the unit to stop. This triggers a chain reaction when the first unit has arrived at it’s position. The downside of this solution is that the units are very arbitrarily positioned when they are at their destination. Screenshot below for a example.

19040-unitformations.png

The green lines are their plotted paths by the way. So if I had not applied the before mentioned algorithm, they would all attempt to reach that single spot.

What I would like to achieve, is for my units to maintain a reasonable formation as much as possible, something like this:

19041-unitformations2.png

Now it doesnt have to be as perfect as in the screenshot above, but at least somewhat like it.

Does anyone have any ideas as to how something like that could be achieved.

where is ur code... i need too same for my project

2 Answers

2

where is ur code… i need too same for my project

You have to create a list with size equal to your unit, create others location base on the location you want your units move, and create virtual positions for your unit.
Please check my draft below, i hope it can help you. @Noxrawr

void CreateVirtualLocation(){
List<YourUnit> units; // your unit
List<Vector3> unitPositions = new List<Vector3>();
int uCount = units.Count; //units you want to move
Vector3 basePosition = Vector3.zero; //your destination;
//get half size from the left.
Vector3 leftSide = Vector3.left * (uCount / 2f);
int colCount = 4;//total column you want
int currentCol = 0;
for(int i =0; i < uCount; i++){
if(i % colCount == 0){
//increase column
colCount ++;
}

Vector3 fakeDest = basePosition + leftSide + Vector3.right * uCount;
fakeDest += Vector3.back *  currentCol; 
unitPositions.Add(fakeDest);//you must validate this position is walkable or not before add it to the list
}
//then just move units to fake position you created 
for(int i =0; i< units.Count; i++){
units_.SetDestination(unitPositions*);*_

}