Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Unreachable Target

Discussion in 'Navigation' started by YodelYum, Dec 6, 2015.

  1. YodelYum

    YodelYum

    Joined:
    Apr 3, 2013
    Posts:
    44
    Hi forum, im pretty new to Pathfinding in Unity and stumbled upon this issue:
    I have an agent that tryies to track down the player. Now my problem is, what happens when the player is surrounded by obstacles that the enemy cant pass.


    http://imgur.com/wrjaSs2
    How can i tell the agent to ignore the player and instead start to attack the obstacles?



    Thanks in advane
     
    Last edited: Dec 9, 2015
  2. browne11

    browne11

    Joined:
    Apr 30, 2015
    Posts:
    128
    Take a look at SetPath. I believe you can use this to check if the path is reachable. You could probably use a if statement to figure out what to hit next.
     
  3. pixxelbob

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    Actually NavMeshAgent.CalculatePath is what you want.

    It will return a path with a status of NavMeshPathStatus.PathPartial

    Code (CSharp):
    1. agent = GetComponent<NavMeshAgent>();
    2. NavMeshPath path = new NavMeshPath();
    3. agent.CalculatePath(target.position, path);
    4. if (path.status == NavMeshPathStatus.PathPartial) {
    5.     // target point is not reachable
    6. }
     
    Last edited: Feb 22, 2016
    Khounine and JBR-games like this.