How To: AI navmesh agents to avoid "clumping" "merging" "jostling" into one another

Hi,
I have come across a probelm where local avoidance doesn’t appear to work with large groups of agents all going to the same position.

In an example scene with 100 lets say agents setDestination(target.transform.posistion);

The 100 agents will move to the target and then start to clump and pop into one another and do some rather odd behaviour.

Is there a settings to remove this?

Each agent has a capsule collider and Obstacle avoidanec is on and set to high.

1 Like

Maybe try adding a NavMeshObstacle to them? However this is likely to end up causing issues and cause them to be gridlocked.

thanks for the reply Storm102, i had already considered that as an apporach but just doesn’t seem to be a great solution as you point out, must be some neat solution to this issue.

1 Like

If every agent is walking to the same position avoidance will not work anymore especially if every agent has the same avoidance priority set. Where should they go? They wan’t to reach one position and push each other around.

So instead of walking to target.position take the whole group, calculate the center, take each agent offset and let them walk to target.position + offset. If you have agents which are more important to reach a certain position, set your avoidance priority accordingly. Play with the different avoidance parameters to get your desired results.

Adding a NavMeshObstacle will only work if the NavMeshAgent is disabled compeletly otherwise the agent will behave in a weird way. If an agent reached a certain position you could switch the agent off and activate the obstalce. Nonethless it is far from an optimal solution, as the agent is not able to move unless you switch the obstacle off again.

1 Like

OK, but this does not help when they should attack one target, right?

E.g. in a RTS click attack on a target. They should try to get to the same pos but still avoid each other.

Get points around the mesh by sampling the mesh’s bounds. Create an array of points, then give each agent a random position.

Your idea was perfect When an enemy is collidering with the player I made it stop and enable an obstacle while this is active the other enemies no longer not push each other. Thank you :smile:

1 Like

Increase the NavmeshAgent Radius It works pretty well!

This Worked Great i just enabled carve and that helps a Lot too