Problem with AI and pathfinding.

I have a problem with my AI. I use unity’s navmesh agent solution to order my AI enemies to go to the player


but when there are other agents surrounding the player (i.e. the direct path is obstructed by other agents) the enemy freaks out, changing direction every frame.
The video below describes my problem better:

I should note that my AI agents behave fine when there are only few of them and they do not surround the player.

Any help much appreciated.

I ended up using Navmeshagent.path.corners[1] to point my sprite in the direction of the target. The agents still move like on the video but their sprites don’t change so rapidly so it’s much better this way.

The target.position is the players position, right?

So essentially you’re telling every single AI to go to the players position. Which is already occupied by the player.

You can easily get around this by telling your AI to stop, say 2 units from the player or something, but you still end up with this problem.

Just because you use the same navmesh for every AI doesn’t mean they are aware of eachother. Essentially they are all trying to stand in the same place, but are all blocked by, or pushed by eachother. As you have more AI trying to get to the player, you’re more likely to have AI trying to stand in the same spot.