Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question How can an agent figure out which doors lead to it's destination?

Discussion in 'Navigation' started by babaliaris, Dec 30, 2020.

  1. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    40
    I'm creating a game and the enemy must somehow figure out which doors can lead to the destination where he's trying to travel and pick the closest one.

    I know how to figure out the closest door using the distance between the door and the enemy, but how can I know which doors can actually open the path for the agent so he can travel to its final destination?

    My doors are using a navmesh obstacle component with carve enabled. I'm using the calculatePath() to figure out what to do with the agent:

    1) If the path is partial, then all the doors that lead to its destination are definetly closed.

    But after that how do I figure out which doors can the enemy open in order to reach its destination?

    Thank you for your time :)
     
  2. babaliaris

    babaliaris

    Joined:
    Apr 21, 2013
    Posts:
    40
    Ok, it turns out that If I disable the carve option in the navmesh obstacle component, the agent already knows which path to follow in order to reach the final destination, and he will move towards the door that he is supposed to open and if he reaches the door "close enough", he can open it.

    But this introduces another problem:

    1) What if the agent on his way, passes a door "close enough" which he is not supposed to open?

    If my logic says "If the agent enters the door trigger, open the door" the enemy can accidentally open doors that he is not supposed to. So I still need to figure out a way to know if the agent needs to open a door obstacle in order to reach the final destination.

    Also, I can't use the CalculatePath() method, because obstacles with the carve option disabled, always yield the PathComplete result of the CalculatePath() method.