Saturday 4 February 2017

AI Teams, Unit Health and Basic Combat

AI teams








The teams are represented by a public integer so the information can be accessed by other AI units. At the moment there are only two teams, 0 and 1. When the program starts, I check whether the unit is in team 1 or 0; if it's on team 1 then I colour the mesh red.



Health

The health is represented by the blue numbers. In order to display the health on the screen, I used Unity's OnGUI function. The function loops through each AI unit, gets the position relative to the screen, and renders the text on the screen in the appropriate position each frame.

Combat

On each frame, each unit checks a sphere with a radius of 2 to check if there is any AI nearby; if the AI is on the enemy team, is not the current target and the current unit is not attacking anything else, then the "attack" co-routine is run. Whilst the target is still alive and within the radius, then the current unit attacks and takes 1 health from the enemy AI per 0.5s.

Finished Result: