Specialization

My Specialization is to create a Real Time Strategy like coordinated army AI in Unity

Motivation

AI is an area  in programming that has always interested me because of the large amount feedback that it creates from very little input. 

The uncertainty of how AI will act keeps me interest long after I understand the controls of the game.

One game franchise that I think shows this particularly well is Total War. 

I have spent countles hours just playing custom battles combining

different armies to see how they will defeat each other.

Because of the enjoyment i have playing RTS games such as the Total War games a lot of my own game ideas are usually centered around coordinated AI. Therefore i chose to create a coordinated army AI similar to Total War: Warhammer.

Army Slots

The first step to achieve army like behavior was to give slots to the soldiers in the army. 

Firstly I created an Army manager that spawned the soldiers in their

desired positions. 

Next step was to assign a new position to the army which was when the

slots came into importance. 

At first slots were just arbitrary positions calculated from the center and

slot index. 

This worked well until it was time to rotate the army which brought a

myriad of needed calculations that i realized would be easily avoided with unity's parenting system. 

Using the slots as game objects themselves their transform will rotate around the parent on their own.
With the slots in the right position and a seek behavior the soldiers walked to their desired position without a problem.



Army Repositioning

Although the soldiers now walked to their desired position they didn't do it in a efficient way one would expect from a coordinated army.

The next step was to redistribute the slots to each soldier so that the path to their slot was at a more even distance between them. 

As a result the soldier furthest from its slot will take less time to reach its destination and the reassembly of the army will be quicker. 

Upon a quick examination of how Total War: Warhammer handles this problem i came to the conclusion that they simply assign the soldier to the closest slot that is the furthest away from the army And iterate through all the  slots. 

This unfortunately created a wavy resembling reassembly of the army because of the redistribution not being very even in all cases.

After a long time analyzing I realized that the slots should be assigned to the soldier that had the closest distance to the average distance between them all. 

The end result was a repositioning that seemed less artificial but still more efficient. 



Coordinated Army Attack

To complete the combat ready army it just needed to attack the opposing army. This seems simple enough by just having the front row of the army attacking until a front slot soldier eventually needs to be replaced by one in the back. But presumably to imitate the uncoordinated nature of a life or death situation the armies of Total War aren't as structured during combat. To imitate Total war the army needs to completely break formation along its width but still keep its length. By simply assigning desired targets to the entire army instead of the front row the soldiers ignored their slots to try to reach their target. The formation was now broken. 



Conclusion

In the end i'm quite happy with the result. the soldiers act fairly similar to how they act in the Total war franchise. Even though I'm happy with the result i underestimated the amount of time it would take to create an army like this. I had planned in a fair amount of performance fixing to allow for a bigger army. The total war games can have thousands of soldiers on the battle field but mine started lagging at 300 hundred. Finding ways to make the coordination between the agents efficient is an important part of RTS games that i didn't manage to cover. But I still got my army and had a lot of fun making it.