Search Unity

Question NavMeshAgent stops or even turns away from destination while agent.destination is still correct

Discussion in 'Navigation' started by Nico7195, Dec 2, 2023.

  1. Nico7195

    Nico7195

    Joined:
    Mar 31, 2023
    Posts:
    4
    Hey there,

    I have been struggling with that issue for a long time and have eliminated one possible error source after the next but for the love of god, it is still happening.

    My agents are successfully patrolling between two fixed points. Everything is on one NavMeshSurface, no obstacles, no holes in the mesh, no off-mesh links, obstacle avoidance quality of the agents is set to none. So far so good. They basically go absolutely straight and turn 180 degrees between the two points, back and forth.

    BUT every once in a while, they stop or even turn around for a few seconds at one specific point (always the exact same spot) on the same route they already did many times successfully, before continuing their journey as intended.

    agent.remainingDistance seems to show that something has changed in the path while they do it since it jumps from 40 to 100 and then back down again (which suggests that they switch the destination back to the last visited spot and then again to the right one after a few seconds).
    BUT at the same time, Debug.Log confirms that agent.destination still contains the position they are supposed to go to next and it does not change while agent.remainingDistance is jumping back and forth. How can agent.destination and agent.remainingDistance not be corresponding to the same transform position for multiple SECONDS? And why does that only happen once every few trips?

    Any ideas greatly appreciated.
     
  2. Nico7195

    Nico7195

    Joined:
    Mar 31, 2023
    Posts:
    4
    Basically found a "fix" just now by writing out the issue, but it seems odd and I have a feeling that it might be a bug in the navigation package (or at least a form of behaviour that should be mentioned or warned of):

    One point was at 0,0,0 and one at -100,0,-100 and the problem occured.

    Now I just moved everything away from negative and zero-values (500,0,500 and 400,0,400) and now the problem seems to be gone.

    Hope this helps anyone with a similar issue!
     
  3. Nico7195

    Nico7195

    Joined:
    Mar 31, 2023
    Posts:
    4
    Well, celebrated too early. Now it is happening when coming from the other direction. Seems like the agents are struggling when speed has values < 0 while destination values or its own position are > 0 and vice versa. Only happens then and again it happens at the same distance it did before. Really am at a loss here.
     
    kevinbrizuela777 likes this.
  4. adriant

    adriant

    Unity Technologies

    Joined:
    Nov 1, 2016
    Posts:
    69
    Nico7195 likes this.
  5. Nico7195

    Nico7195

    Joined:
    Mar 31, 2023
    Posts:
    4
    Hey @adriant,

    thank you very much for that hint. My agents were travelling along the edges of two tiles all the time. I rotated the surface a little bit and it seems to have done the trick.
    Many thanks!