## AI behavior : Circling Enemies

It is an AI behavior which involves enemy game object being spawned and circling the player equidistantly.

The circle is completely dynamic as more enemies join or are killed , the circle rearranges itself accordingly.

Logic :

It is implemented by dynamically calculating Polar Coordinates for the Enemy Gameobjects in the virtual circle around the player , along with the Navigation Mesh.

Polar Coordinates :

The coordinates of the enemy entities can be calculated in terms of angle from a center point of a circle.

i.e.

x = rSin

y = rCos

The circle is completely dynamic as more enemies join or are killed , the circle rearranges itself accordingly.

Logic :

It is implemented by dynamically calculating Polar Coordinates for the Enemy Gameobjects in the virtual circle around the player , along with the Navigation Mesh.

Polar Coordinates :

The coordinates of the enemy entities can be calculated in terms of angle from a center point of a circle.

i.e.

x = rSin

**θ**y = rCos

**θ**where θ is calculated dynamically for each enemy entity ,

Hence

**θ = [2 ***

**π / No. of enemies active ]**

A List data structure keeps the track of enemies active , i.e. it is updated whenever an enemy is spawned or destroyed.

The new coordinates , y = rCos

**θ**are updated for every active enemy entity.

x= rSin

**θ**

with 'r' being the distance from the player.

These new coordinates are used as destination point in the navigation mesh so they also avoid the obstacles in the path of the circle.