Navmesh agents to avoid other agents

I don’t see how that answers my question. Are you saying you think it’s correct that it’s dangerous? If so, that still doesn’t answer the question of how to make agents avoid each other.
In the 2018 documentation it already said that they don’t mix well together, but it might not be true in the specific case GameDevCouple_I mentioned.

You need to have only one on at a time, otherwise the agent will be trying to avoid itself (since the obstacle is on the same gameobject). This will cause weird behavior.

Moving/Charging:
Switch off NavMeshObstacle
Switch on NavmeshAgent

Fighting/Idling:
Switch on NavMeshObstacle
Switch off NavmeshAgent

This article is somewhat old and the tutorial screenshots don’t work anymore, but it describes exactly whay you need to know.
https://www.gamedev.net/articles/programming/general-and-gameplay-programming/pathfinding-and-local-avoidance-for-rpgrts-games-using-unity-r3703

2 Likes

Thats good unless 2 characters are moving then they wont avoid themselves, thats the problem with unity there is no easy way to do it. I recommend buying A* and using the RVOController to save yourself weeks or months of headache.

2 Likes

That’s true.
But have you tried using NavMesh.CalculatePath()? This way you don’t even need to have a NavMeshAgent on your unit. You could keep the NavMeshObstacle toggled on at all times. That’s what GameDevCouple_I suggests to this issue.

I’m just not sure what the implications of not using a NavMeshAgent are.

Agent have more feature than Calculate path. He has obstacle and agent avoidance, following and returning to path with appropriate handling.

On the other hand, you can implement it. Unfortunately Agent is native component and does not have API

Maybe I am missing something, but Unity NavMesh Agents do avoid each other without any obstacles on them? And you can decide who avoids who using priority.

Maybe I misunderstood what this thread is about, but what A* RVO component does is basically what Unity already does (although a bit nicer).

Hi, I have similar problem, but using navmesh obstacle causes other bigger gameplay problems I want to avoid; such that I want some units to be able to collide and others not.

Thus I was thinking would it be possible to instantiate a (non-walkable area beneath my unit at desired time to avoid other units from approaching that unit of interest) at “run time” and make those specific units use (area Mask)?

Also, if that is possible, how would I reverse the change at run-time?

I would try to solve this using priority instead of editing the navmesh surface at runtime.

@vhman ,

in my experience, this will stop the pushing, but it doesn’t avoid the bumping. Normally when you bump you add force to that unit and nudges it also. however if the unit you bump into has higher priority, you still bump into it and can get stuck trying to pass it, but you do not nudge it.

the question is, how to avoid it, or make a cleaner path that goes around and completely avoids the point of interest without using navmesh-Obstacle?

I made a video to show you the problem, Also; ignore what happens after 4:10 in the video, that happend because the priority of all units changed to the same value (as part of my game mechanic)

https://www.youtube.com/watch?v=67uk0PhuTG8

Isnt this the exact same scenario as above? i.e when they start to attack just add an obstacle to them and the agents behind will go around?

As message addressed to me, I will take a try to respond.

Essentially you want Repathing, so that path changes dynamically in a response to moved agent, and not Avoidance, that is like a bubble you cannot penetrate.


For repathing you need to change navigation mesh dynamically, and obviously the only API we have is obstacle carving. But be aware that if Agent is carved Obstacle, it would think its not on navmesh. So there is no way to do it without some janky coding. Maybe you can fill the hole under you in moment of CalculatePath().

I’m also not aware of A*RVO details. So no comments

After I saw video:
What you want is RTS movement:

1 Like

@vhman ,

Thank you for reply.

I completely agree, and thats exactly what I want, however its just not working. (it kinda works when all the units are running, but not when some units have already reached their waypoint (as you saw in the video).

and if this is not an option “say I want a tank to always cut through those units”?

This part wont be a problem to me because I will only activate this when my units reach their destination, or even a specific activation time after they have reached their destination. But the problem that still remains, is what if I want a tank to still cut through those units?

Thank you for this Link, I will try to study it, however, I really want to use navmesh/navagent, and I would hate to completely recreate the navmesh/navagent system from scratch. Despite my account creation day, I am a noob, and really only started programming less than 3 months ago give or take.

yes, and if my game would have had only one type of unit, that would have worked, but I wouldn’t want my tank to go around that group of infantry, I would want my tank to cut through as a result of higher priority, and that will no longer be possible if I was to use an “obstacle”. As an obstacle will treat all units the same

You can have NavMesh bake and all its static classes, like point cast and etc. But “RTS like group movement” will require do it from scratch, or use RTS asset, or even other RTS game engine. Agent are not RTS group friendly.

I wish Unity, would give more flexibility and more options when it comes to the navmeshAgent. but I think I have a solution! the problem is when the units reach their destination, what if I fake navemesh Movements of higher priority on those locations?

nvm, I dont think thats possible, and probably very taxing even if it is possible

I know that the RVO controller in the A* project can do exactly this. Will cost you 100$ tho.

can you provide me a link to this asset please, thank you

Nvm found it, thanks anyway

I have a similar problem. My game (zombies), tend to bump into each other and push each other, in stead of trying to go around them.

I do turn on the Navmesh obstacle when they are stationary, but I want faster zombies to walk AROUND slower ones, instead of just plowing through them.