Search Unity

Using SetDesination, sometimes agents go to roof above me

Discussion in 'Navigation' started by radiantboy, Mar 3, 2020.

  1. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    So I have a ton of agents following me using setDestination, it works well... until I go inside a building, then they tend to go on the roof and stand exactly above me, obviously I want them to follow me into the building. The nav mesh shows that they can so I am wondering why they wont... My patrolling enemies have no problems getting to waypoints in the building so it's strange. If I leave and slowly tease them in, they do come in.. any ideas?
     
  2. DwinTeimlon

    DwinTeimlon

    Joined:
    Feb 25, 2016
    Posts:
    300
    Can you post a screenshot of your navmesh?
     
  3. Lork

    Lork

    Joined:
    Jul 12, 2013
    Posts:
    79
    When given a choice while determining the closest point on the navmesh to a given destination, NavmeshAgent seems to almost always choose the point above it, even if the ground below it is way closer.

    Try setting your destinations closer to or exactly at floor level (eg. by raycasting down to find the precise point).
     
    Last edited: Mar 12, 2020
    radiantboy likes this.
  4. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Actually it looks like since my player has a navmesh obstacle on it, they go above, removing that allows them to mostly go to to the right spot. The problem is I need this for various things, I wonder how I can get some to ignore the obstacle, but I guess there is no way. Maybe if I give them a spot just outside the obstacle it will work.

    awesome this more or less works :)
    Code (CSharp):
    1. float randomExtra = Random.Range(0.5f,1.5f);
    2. Vector3 justOutSideTarget = new Vector3(currentTargetObject.position.x+ randomExtra, currentTargetObject.position.y, currentTargetObject.position.z+ randomExtra);                  
    3. setDestination(justOutSideTarget);
     
    Last edited: Jan 17, 2021
  5. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Got this again recently, seems to also happen if the navagent is too tall to get in somewhere (like a door to an interior), so they instead go above it.