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.