Search Unity

Can NavMesh detect open and closed doors?

Discussion in 'Navigation' started by Lethn, Apr 24, 2016.

  1. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    What would be the way to check whether doors are open and closed or not? Is the NavMesh system capable of detecting whether a certain part of the navmesh is changed? I'm aware that it can detect stuff dynamically moving but I was just wondering how good it is. It seems like with detecting objects fallen to the ground and so on that I would need to use invisible colliders and so on to help the Agents figure out what is there and what isn't.

    I'm thinking of very simple stuff, like sliding doors that you see in a lot of management games and so on.
     
    Eiseno likes this.
  2. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    The agent by itself does not see anything specific; if it is not in the baked navmesh, the agent use the colliders I believe, to avoid them, but it is not working very well, and it is a waste of resources (at least in my case, it would get stuck).

    The navmesh agent has a collider to interact with other agents I believe, while you still need a regular collider for all the other interactions.

    You can add dynamically an obstacle component, and set it to carve, so the agent will deal with it more easily. Even if the navmesh is not interrupted, you can place a door and use it as obstacle; when you want the agent to go through the door, you perform the animation to open the door and resume the agent so it will head toward the target.
     
    Lethn likes this.
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Thanks for that, cleared things up, now that I'm learning more of the basics I'm having a closer look at all the detail of what the engine is capable of.
     
  4. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    THe best way to figure out something is to try it; I did notice that the docs in Unity are somehow lacking in many aspects, so you can't just go through the docs, without give it a try too.

    Opening a door is pretty straight forward; there is a tutorial about it on the Unity youtube channel; they also use agents I believe. Take a look at it and see if it is what you are looking for
     
  5. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,364
    The example project for navmesh has what you need.
    You can also add a navmesh obstacle to your door and toggle on carve.
     
    Last edited: Apr 29, 2016
    JC_LEON likes this.
  6. JC_LEON

    JC_LEON

    Joined:
    May 20, 2014
    Posts:
    520
    sorry for necroposting but which tutorial are you refferring to?
     
  7. rapidrunner

    rapidrunner

    Joined:
    Jun 11, 2008
    Posts:
    944
    It is ancient now


    There are few more recent that does explain it with more updated version of unity, but fundamentally the gist is the same.

    In short; make the door open with a trigger, like you would do in any other example, and when the agent move, it will open the door. The trick is to not make the door part of the wall, otherwise the agent will get stuck. Or you can make the door as "obstacle" and dynamically modify the navmesh, based if the door is locked or can be opened by the agent
     
    Last edited: May 27, 2019