Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Navigation' started by Ardinius, Aug 6, 2017.

  1. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    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.
     
    Last edited: Aug 10, 2017
    Roger-W likes this.
  2. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Maybe try adding a NavMeshObstacle to them? However this is likely to end up causing issues and cause them to be gridlocked.
     
  3. Ardinius

    Ardinius

    Joined:
    Oct 4, 2015
    Posts:
    57
    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.
     
    Stormy102 likes this.
  4. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    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.
     
    Stormy102 likes this.
  5. obiwarn

    obiwarn

    Joined:
    Jan 30, 2018
    Posts:
    1
    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.
     
  6. Stormy102

    Stormy102

    Joined:
    Jan 17, 2014
    Posts:
    495
    Get points around the mesh by sampling the mesh's bounds. Create an array of points, then give each agent a random position.
     
  7. Gigoorin

    Gigoorin

    Joined:
    Mar 5, 2018
    Posts:
    2
    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 :D
     
    DwinTeimlon likes this.
  8. tulimound56

    tulimound56

    Joined:
    Apr 10, 2018
    Posts:
    3
    Increase the NavmeshAgent Radius It works pretty well!
     
  9. Nacho53

    Nacho53

    Joined:
    Dec 15, 2019
    Posts:
    1
    This Worked Great i just enabled carve and that helps a Lot too