Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by RichMakeGame · May 26, 2012 at 11:06 PM · navmeshagentnavigationdoor

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

Comment
Add comment · Show 6
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image castor · Sep 25, 2012 at 03:05 PM 0
Share

I'm currently having the exact same problem. I looked at the documentation, the navmesh demos and the $$anonymous$$anual and can't figure it out... should we use the off mesh link? That seems to be for gaps or for certain characters to use certain routes... Any help really appreciated!

avatar image castor · Sep 25, 2012 at 09:30 PM 0
Share

I've been playing a bit more and understand how to place certain navmesh sections into different layers and by changing the walkable$$anonymous$$ask for the agent he is able or unable to walk there. But I still cant figure out how to use the Offmesh link for doors...

avatar image drawcode · Sep 25, 2012 at 09:39 PM 1
Share

Where does the door go though? Another option is making the door dynamic navmeshagents that can shut and open. If you don't have too many that would be pretty cheap.

avatar image castor · Sep 25, 2012 at 10:03 PM 0
Share

I've read an answer here were someone mentioned that but I don't know how to set it up and can't understand how it would fix it. If a navmeshAgent takes all the path space then the path for the other agent becomes invalid?

Also in my case I can stop the agent from going into the room since the door collision is blocking him when the door is closed but he just keeps walking forwards trying to pass through it. He doesn't really detect that the path is impossible. Would the navmeshAgent solution fix it?

avatar image castor · Sep 25, 2012 at 10:41 PM 0
Share

In my case its a top down view kind of game. The player can click directly on the room he wants to go into but if the door is closed the path should be just impossible and he wouldn't move.If its open he can walk there.

Show more comments

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by drawcode · Sep 25, 2012 at 09:38 PM

I haven't tested this but you can activate or deactivate an OffMeshLink: http://docs.unity3d.com/Documentation/Components/class-OffMeshLink.html

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.

Comment
Add comment · Show 15 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image castor · Sep 25, 2012 at 10:33 PM 0
Share

Yeah, I tried to use these but I couldn't get any results.. Also in the Unity demos (http://beta.unity3d.com/3.5-preview/Nav$$anonymous$$eshTest-3.5.0f1.zip) they don't seem to use the dynamic offmeshlink that you are suggesting but actually the static one.

Also those off-mesh links, at least looking at the image, won't they make the player jump from pointA to pointB ins$$anonymous$$d of navigating it properly? I'm going to try something this evening and post the code here to see if it helps understanding why I cant get it to work

avatar image castor · Sep 26, 2012 at 08:27 PM 0
Share

I added a offmesh link to the surface near the door and activating or de-activating doesnt seem to do a difference for the character, he can always cross it. Also from looking at the documentation it says the off-mesh links are for "It is possible that the navmesh static geometry in the scene is disconnected, thus making it impossible for agents to get from one part of the world to the other"

Which is not the case...I just want the path to a certain location to be blocked temporarly. I think its related to navmesh layers but I cant figure it out... help would be really good

avatar image RichMakeGame · Sep 26, 2012 at 09:08 PM 0
Share

I've moved on to something else at the moment, but as an idea could you create a nav layer that only covers the area of the door? and on the base layer create a gap in the door threshold. Then when the door layer is enabled the layers overlap and create a path. Having a layer for every door doesn't sound ideal if you have many doors though. I have a feeling this system isn't entirely complete

avatar image castor · Sep 26, 2012 at 09:20 PM 0
Share

Yeah, I can see how that would work but in my case I would need too many layers...Also the player still tries to get there, he just stops on the boundary between the 2 layers...

I noticed that you can do a pathStatus and you get a "pathPartial" ins$$anonymous$$d of "pathCompleted" if I use your suggestion maybe I can use that to stop the player from even moving.

But still it feels like extremely complicated and I have too many rooms with too many doors to have this work nicely. Also if I use layers I would end up having to change what layer each player can use ins$$anonymous$$d of changin the current navmesh layer and thus making the doors independent from the characters and just more clean overall... I'm sure there must be an answer to this!

avatar image castor · Sep 27, 2012 at 04:15 AM 0
Share

Ok, I've resorted to using Rich$$anonymous$$akeGame suggestion and placing each door in a different Nav Layer. But now how do I set the walkable$$anonymous$$ask based on what doors are open or closed? Those are set as bitfields so I have no idea how to do all the possible combinations.

Show more comments
avatar image
1

Answer by CouldNotThinkOfOneSorry · Jul 23, 2016 at 07:43 AM

@RichMakeGame Try looking at this:

https://docs.unity3d.com/Manual/nav-AreasAndCosts.html

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 (https://docs.unity3d.com/ScriptReference/NavMeshAgent-isPathStale.html).

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).

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by MarkD · Oct 26, 2013 at 05:08 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by rogodoy · Mar 11, 2021 at 01:10 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

NavMesh issue with spawning players 3 Answers

Navigation Agent "Clipping" (Going inside) Navmesh Deadzone?... 1 Answer

Constantly generating Navmesh destination for endless runner game 0 Answers

Interactable object as navmesh obstacle.,How can I make an object interactable while it's a navmesh object? 0 Answers

Enemies using navmesh are bumping each other through solid objects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges