Search Unity

(MOST)Agents won't reach the final destination

Discussion in 'Navigation' started by SparrowGS, May 25, 2018.

  1. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Hey, so i'm doing a 3D shooter with TD elements, the agent spawn in a circle around the center of the map(that's 0,0,0 in world space).

    this worked for the last month or so(since i implemented it), now all i've done is rebake the navmesh because i changed the terrain a bit and it's barley working, using Unity 2017.4.3

    as you can see, all but 2 in this case are stopping way before they reach the destination needed, I have no idea why this is happening.

    as far as i can tell the red line indicated the path the agent will follow, i don't know what the orange circle and lines mean, I looked over (I think) all the navmesh and navmeshagent docs i could find, didn't answer any of these questions.

    this is the code that controls the agent:
    Code (CSharp):
    1. protected override ManualUpdate(){
    2.         if (agent.hasPath == false && agent.pathPending == false) {
    3.             if (agent.SetDestination (Vector3.zero) == false) {
    4.                 Debug.LogError (string.Format ("Agent at:{0}, can't get a path!", transform.position)); //This have never showed up
    5.             }
    6.         }
    7. }
    8.  
    9. public override void Ini (){
    10.  
    11.         agent = GetComponent<NavMeshAgent> ();
    12.         agent.stoppingDistance = minRange;
    13.         sqrSpeed = agent.speed * agent.speed;
    14.     }
    15.  
    16. public override void SpawnObj (Vector3 pos){
    17.  
    18.         if (agent.Warp (pos) == false)
    19.             Debug.LogWarning (string.Format ("Enemy {0} couldn't reach target position! {1}", transform.name, pos));
    20.         agent.ResetPath ();
    21.     }
     

    Attached Files:

  2. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    Does any one have any idea?
    or at least knows what the orange circles and lines represent in the navigation window?
     
  3. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    So I just did some more testing and if the agent is like at the picture name "Nav1" and i manually move him closer than(or then?) the orange circle it immediately turn to a red line and it walks fine to the center.

    The F***?
     
  4. SparrowGS

    SparrowGS

    Joined:
    Apr 6, 2017
    Posts:
    2,536
    So I sort of fixed it, i figured out that the orange line indicates where the path goes stale, I have no idea why because the docs say "This flag will be set if: there are any changes to the areaMask, if any OffMeshLink is enabled or disabled, or if the costs for the NavMeshAreas have been change" I don't do any of that, but it still goes off.

    they way i worked it out for now is like this
    Code (CSharp):
    1.         if ((agent.hasPath == false || agent.isPathStale) && agent.pathPending == false) {
    2.             if (agent.SetDestination (Vector3.zero) == false) {
    3.                 Debug.LogError (string.Format ("Agent at:{0}, can't get a path!", transform.position));
    4.             }
    5.         }
    BUT I'm extremely unhappy with this code, it runs way too much, and the agents that can't get a full(not stale) path from the get go will calculate a path for every navmesh polygon between the orange circle and the real destination.

    please, help, someone from the unity team, i'm lost, what's happening here?