Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

NavMeshAgents not avoiding one another (obstacleAvoidanceType bug?)

Discussion in 'Editor & General Support' started by OneThree, Aug 5, 2012.

  1. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    I'm using 3.5's pathfinding, and it mostly works completely fine. I'm using it in an environment with a good navmesh, and I'm simply using SetDestination to move them around.

    I've noticed, however, that sometimes two agents will happen to cross paths while going to their destinations, and they just walk against each other.

    They don't make any attempt to avoid one another, and they just walk against each other for as long as it takes for their collision cylinders to eventually slide around the other agent and let them continue on their way.

    Auto Repath is set to true for both agents. Obstacle Avoidance Type is set to High Quality for both agents. The agents' physics layer is the same, and is set to collide with itself in the project's physics settings (this is of course evidenced by the fact that they walk against each other as their cylinders slide).

    Am I missing something? Shouldn't obstacle avoidance between two NavMeshAgents cause them to avoid one another more gracefully?
     
  2. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    That usually occurs when you have many Agents moving around. I suspect the avoidance calculation becomes pretty tricky and then Agent sort of fails at being able to avoid the collision.

    Note: Based on my observations, it does seem like Agent do wait until the last moment to take corrective action to avoid a potential collision. I wish we had some control over the avoidance distance.
     
  3. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    This is in a scene with only 3 total NavMesh Agents, so I doubt it's that.

    Can you describe what it's like when your agents avoid one another? Are there any non-obvious settings I should look into? Any scripting tricks?
     
  4. Stephan-B

    Stephan-B

    Unity Technologies

    Joined:
    Feb 23, 2011
    Posts:
    2,269
    Normally when you have one of the Agent selected, in the Editor view, you can see debug lines being drawn. I believe the Green line represents the avoidance.

    In terms of their behavior, I noticed that when two Agents are moving towards each other. They will wait until the last possible moment to turn to their right to avoid the collision. I think they make subtle speed adjustments to attempt to avoid the collision but at the last moment resort to turning right.

    Seems like if they made that turn a bit earlier, it would reduce their stress level as making that last second turn must be unnerving for them. Like oh S***! oh S***! ... ahhhh turn ... ouff! :)
     
  5. Battleb

    Battleb

    Joined:
    Feb 23, 2012
    Posts:
    85
    hm, you make it sound really funny, but this is an actual problem i've been asking for some time as well, but no real answer from Unity. What's the point on having a really good navmesh based system if agents just walk on each other?
    So, please Unity, give us some clues, at least tell us how to fix this!!
     
  6. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    Yeah, the avoidance stuff in Unity is really poor. I'm pretty sure I'm gonna have to end up writing some sort of hack solution to deal with it. It's especially bad if one character is standing still and the other's path happens to go through the stationary agent.
     
  7. mrpooley92

    mrpooley92

    Joined:
    Sep 15, 2013
    Posts:
    19
    bump issue still persists
     
  8. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    144
    Have there been any improvements to this in Unity over the year? I tried scripting Navmesh Agents to disable their navmesh and become navmesh obstacles at appropriate times (such as when they're stationary doing an important task) to get other navmesh agents to repath around them. It kind of works, but spits out tons of errors during run time and nav agents eventually stop working or Unity crashes, whatever happens first.

    I know there's some assets that have dynamic avoidance but aside from this issue, I really like Unity's navmesh and agents, so I'd prefer to work with them. Anyone have any tips for dealing with this?
     
  9. Ziron999

    Ziron999

    Joined:
    Jan 22, 2014
    Posts:
    260
    February *bump* issue still exists lol
     
  10. HarpSeal1

    HarpSeal1

    Joined:
    Oct 23, 2013
    Posts:
    35
    I too was having this problem. Turns out all of my agents had the same obstacle avoidance priority. So on start I assign a random priority from 1 to 100. It works well if the two agents aren't near the edge of the nav mesh or on a narrow path. When they are, the lower priority agent (higher number) can't steer out of the way and gets plowed. I wonder if there is a solution to keeping them from the edges.
     
  11. Jwolf

    Jwolf

    Joined:
    Sep 8, 2013
    Posts:
    15
    Worked for me. Thanks.
     
  12. LeftyTwoGuns

    LeftyTwoGuns

    Joined:
    Jan 3, 2013
    Posts:
    144
    That could have been my issue as the level I was testing it had a lot of narrow corridors, which would put the agents at the edge of the nav mesh more times than not. Did Unity 5 add any improvements to nav mesh agents?
     
  13. HarpSeal1

    HarpSeal1

    Joined:
    Oct 23, 2013
    Posts:
    35
    I can't see any unfortunately. Perhaps if enough people wanted navmeshagent improvement Unity might look into it. Id really like agents to repath if another agent is blocking a narrow path! Maybe there is a way to do this with the current system though and I'm just unaware.
     
  14. Phuzz

    Phuzz

    Joined:
    Mar 31, 2014
    Posts:
    47
    Worked for Me, I guess this is a good workaround in most cases.

    Thank you
     
  15. Harinezumi

    Harinezumi

    Joined:
    Jan 7, 2013
    Posts:
    53
    I hope you don't mind me necroing this thread... :p

    I'm heavily relying on NavmeshAgents in my game, and ran into the same problem, them not avoiding each other. I used Navmesh obstacles with carving turned off, and it seems to work a lot better than avoidance priority. Have you tried that?

    Here's what the manual says:
    http://docs.unity3d.com/Manual/class-NavMeshObstacle.html

    Cheers!
     
    JBR-games likes this.
  16. Vodolazz

    Vodolazz

    Joined:
    May 23, 2016
    Posts:
    2
    Thanks buddy that works really perfect now. And protects from sliding even if navmeshagents are stucked into each other.
     
  17. xxhaissamxx

    xxhaissamxx

    Joined:
    Jan 12, 2015
    Posts:
    131
    i used it but my AI move very fast i don't know why ?
     
    JamesArndt likes this.
  18. nonstandardstudio

    nonstandardstudio

    Joined:
    Apr 25, 2017
    Posts:
    1
    I'm using rigidbody component with Collision Detection set on Continuous Dynamic...works perfectly for me
     
    xxhaissamxx likes this.
  19. ashutoshvfx14

    ashutoshvfx14

    Joined:
    Jul 1, 2018
    Posts:
    1
    This Worked Like A Charm!!!
    Thanks
     
unityunity