NavMeshAgents not avoiding one another (obstacleAvoidanceType bug?)

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?

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.

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?

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 shit! oh Shit! … ahhhh turn … ouff! :slight_smile:

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!!

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.

bump issue still persists

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?

February bump issue still exists lol

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.

4 Likes

Worked for me. Thanks.

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?

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.

Worked for Me, I guess this is a good workaround in most cases.

Thank you

I hope you don’t mind me necroing this thread… :stuck_out_tongue:

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!

1 Like

Thanks buddy that works really perfect now. And protects from sliding even if navmeshagents are stucked into each other.

i used it but my AI move very fast i don’t know why ?

1 Like

I’m using rigidbody component with Collision Detection set on Continuous Dynamic…works perfectly for me

1 Like

This Worked Like A Charm!!!
Thanks