NavMeshAgent and doors?

The help page on navigation mentions the complex environments of games and the obstacles within, such as doors- but stops short of explaining how to manage these circumstances.

Can anyone tell me how I could manage a scenario where a door could be locked or open, and tell a nav mesh agent to to around or through the door depending on its state?

Thanks,
-Rich

I haven’t tested this but you can activate or deactivate an OffMeshLink:

Your script could find the OffMeshLink and activate or deactivate the link based on the door condition.

Activated Specifies if this link is actually used by the pathfinder. When this property is false, the off-mesh link will be disregarded. This property is runtime-editable, and does not require a re-bake.

@RichMakeGame Try looking at this:

This link explains NavMesh areas and costs. I have yet to actually try it, but here’s my quick/TL;DR understanding:

  1. You can select meshes you character will walk on, and specify a NavMesh area.

  2. This area can then have it’s cost altered. The NavMeshAgent/s that use the NavMesh will automagically prefer routes with lower costs. [=>]

  3. This area can also be excluded from a NavMeshAgent’s AreaMask. Doing this stops the NavMeshAgent from walking through this area; the example from the manual is a Zombie being unable to open a door, but you could also have a system where you need a key to open a door. [==>]

Hope this helped. Sorry if you figured this out 4 years ago. :\

=> An example of this could be something like trying to traverse a river by bridge vs wading through waist-high water - you’d much rather walk on the bridge, because it’s faster (has a lower cost).
BUT, if the bridge is far away, and the destination is directly across from you, then wading may be faster (have a lower cost).

==> To do this, you might fire an event that changes the NavMeshAgent’s AreaMask ([VariableForNavMeshAgent].areaMask = ???) when your NavMeshAgent touches a mcguffin.

NOTE: Changing Off-Mesh links (enabling/disabling), NavMesh area costs or NavMeshAgent AreaMasks sets the “isPathStale” flag to true (Unity - Scripting API: AI.NavMeshAgent.isPathStale).

If the path is stale, it indicates the path may no longer be valid (not sure here, sorry) or optimal (bridge/river example: if you have boots that let you walk on water (it’s a game :p), walking the 1km to a bridge, across it, then 1km to a goal is MUCH slower than walking across the 500m river).

all suggestions are good. what i have done once is to create a mesh (like a plane) in the shape of the floor. then only let it calculate its mesh path on that object. this way you will have a path wich is the same as your floor without doors. another thing you could do is to dissable the doors on the moment of baking and re-enable them after the bake. if it needs to interact place a trigger that detects the ai and let the ai wait and open or close the door/other functions

To work with doors and collision in nav mesh, try use “nav mesh obstacle” in the objects you want collinsion, it acts like box collider in nav mesh.