Navmesh Enemy AI, Encircle Target

This post here: Get NavMeshAgents (Enemies) to not bunch up together - Questions & Answers - Unity Discussions pretty much sums up my frustration. Sadly, there was no working answer. My project is in 2D. Is there any way to get the enemy AI to encircle their target instead of all funneling in on side and pushing each other? It would be ideal for the horde of enemies to surround their target instead of just piling on in just one direction.

You just have write a lot of your own behavior code for AI on navmesh. Sadly that’s just how the nav AI system is. It’s not fleshed out and able to do anything much in the way of behaviors. No fleeing/flocking/hiding/specific rules for certain obstacles… etc… it’s just a very basic start of a nav system.

2 Likes

Yeah, but you can cheese and cheat the hell out of it. We’re building video games, not rocketships! :wink:

I added a gameobject to my enemy that scoots over to the player’s world position, and then starts orbiting it on the X / Z axis. So basically the player is surrounded by a cloud of objects that are completely invisible. These objects do a RayCast downward and if they hit a NavMeshSurface, they update a Vector3 position in the enemy component.

I simply have the enemies walk to this custom position. I could randomize their path a little further by varying the radius, speed and direction of the orbiter object, but it already feels more like a rushing horde then when I would simply feed them the player position. Remember: cheating is not only allowed, it is fully encouraged.