Navmesh agents to avoid other agents

If you want pushing you cant make them obstacles.
Set priority based on speed.

Yes, I’m doing that but a higher priority (10), still pushes a lower priority (50), if they are in the way.

They never go around them.

Are you saying that you don’t see that issue at all?

if not, then I will have to re-examine my movement code as I’m setting the NavMeshAgent.speed to match the animation rootmotion speed to prevent foot sliding.

I previously was setting navmeshagent.velocity, but changed it to speed when I read in the docs that setting the velocity directly disables avoidance between agents. Maybe I’m still having this issue?

higher Priority is intended to push away lower priority, Lower Priority Cant push higher Priority and equal priority can both push each other.

Also Have noticed that Equal priority only avoids each other if both agents are moving.
and Lower priority moves out of the way of higher priority only if both are moving.

Thats just based on my experiance

I just created a quick script that check avoidance of other Navmesh agent when using avoidance priority.

There is zero effort for slower and less priority agents to move out of the way. Giving the fast agent a higher priority only allows it to plow thru (push them out the way) the lower priority ones.

I’m guessing the only way to get them to avoid each other totally is to put a Navmesh obstacle on them and use my own code to move them instead of the Navmesh agent.

I would love to see a simple example of avoidance in action…I don’t see it.

you can increase the navmesh cost underneath the unit that you want to be avoided, though I am still working on how to do that myself.

You can’t do that at runtime. Navmesh areas need to be baked in at edit time.

you can bake navmeshes at run time also, check this project out.

1 Like

Maybe I should have been more clear. You can bake them during runtime, but its not performant, so it couldn’t be used for real time avoidance. That’s more for scenes that are created or altered procedurally,

For what you suggested, (re-baking the navmesh to change the navmesh cost under an agent), would be way too costly and would not run fast enough for moving agents that are trying to avoid each other.

why is it that we can make dynamic NavMeshObstacle with carve on stationary units and its relatively performant from what I have heard, but altering the local navmesh cost be taxing?

Anyway, I have seem to have found a temporary solution for this problem, add the following to your NavMeshAgents.

Note: the lower the value the better avoidance quality, but it also becomes more taxing, I think I can further Increase this quality by reducing the VoxelSize, but I cant seem to figure out how to do that, ofc that also makes it more taxing.

void Start()
    {
       
        NavMesh.avoidancePredictionTime = 0.5f;

    }

Its because baking a navmesh uses a lot of resources, that’s why its done offline. Its completely different than using a NavMeshObstacle.

By the way, you don’t need to use carve to have it not go through another agent. Carve actually puts a whole in the Navmesh, less performant prevents other agents from calculating a path through it, which would be a problem in something like a doorway. Using it without carve prevents the agent from moving through it, but also allows it to calulate a path.

It really depends on your use case, but just letting you know that you don’t have to use carve.

Problem I have, is that I do need it to calculate a new path, because if I have several obstacles “without carve”, the units trying to get past will just get stuck. whereas if they had “carve on”, they will use a new path and thus they wont get stuck.

Now the thing is, obstacle avoidance works exactly the same as having the other Unit that you want to avoid with Higher priority which is more convenient (correct me if I am wrong). The biggest problem is, both these features are not good enough and they look quite unnatural, thats why I wanted to just increase the cost in the area that I want to be avoided, but under high stress that area will still be usable (basically what ever ends up costing less).

Now, I know one extremely costly way to do this, and that is to divide the map into a grid (small squares), and each division/square having there own tiny navMesh, then I can just change the cost of the navmesh that I am standing on. but in my experience, that will be extremely costly. I may as well make my own A* Pathfinding, which is ofc something I am trying to avoid.

I had some help on how to change the nav mesh cost, But It was way too advanced for me, and If I am being honest, I didnt understand any part of the code. even though i understood 90% of the explanation.

https://forum.unity.com/threads/how-to-create-a-dynamic-area-cast-in-navmesh.792459/#post-5276964

After I looked at the documentation and test it myself, I’ve noticed that avoidance priority only allows an agent to ignore other agents or not.

Lower Priority

  1. If an agent of the same or lower priority is trying to get past a group of agents, it will slow down and stay behind the others.
  2. If its near the left or right of the group, it will go around.

Higher Priority
2. If an agent of higher priority is trying to get past a group of agents, it will just go through them and push them out the way.

So for them to go around, there would need to some other method.

That sounds way to rigid, too much work and most likely not performant.

Btw, I actually dynamically change the cost of navmesh areas in my game, however, its not done every frame to direct agents around each other.

@FiveFingerStudios ,

Thanks for reply

That would actually be good enough for me, even if its once every second that would still be good enough for what I am trying to achieve.

Thats something I dont mind, however, what I want is for units with the same priority, or lower priority to walk around units of the same priority or higher priority. This works, however, if you have a wall of units, they would not walk around the wall of units. because its not using the path finding system to avoid those units in the first place, its using RVO. Thats why i need the cost system, I want to reroute before I even need to use RVO.

Dude the comment you replied to, I made 4 years ago. The discussion moved on and I have not kept up with this thread, I recommend replying to comments made within the last year next time if you want a decent response

Props to posting this here, I’ve been looking to a good solution that doesn’t break the bank for a few days, I’ll implement and see the difference it makes!

4 Likes

Nav Mesh Agent> Obstacle Avoidance > Quality > None.

It removes the collision between all the Nav mesh agent against each other. And follow the path as it is . I think this should work.

What if you have a moving destination? Then can’t just calculate the path once and turn off NavMeshAgent