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

Navmesh agents randomly stop working

Discussion in 'Navigation' started by PvTGreg, May 6, 2021.

  1. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    Hi,

    My navmesh agents randomly stop working and stop moving to the destination.
    i have lines drawn to there destination in this case its food that they need to go eat.
    it works randomly a few times. sometimes only once. then they set destination and just stop.
    the set destination is called only once then the only code running after that is checking to see if its close enough to eat it.

    really not too sure whats going on.

    i have made sure they are warped to the navmesh properly when they spawn aswell as the food gameobjects
    i have even tried rebaking the navmesh at runtime but they still get stuck
    stuck.PNG
     
  2. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    if i delete the object it does move. will test a few things and report back
     
  3. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    yeah very odd. even if i tell it to select the closest place to the object on the navmesh we are still getting stuck,
    i even checked if the path was valid and apparently it was
     
  4. PvTGreg

    PvTGreg

    Joined:
    Jan 29, 2014
    Posts:
    365
    Fixed it by forcing the agent to move to the destination

    Code (CSharp):
    1. var heading = target.Value.transform.position - transform.position;
    2.         var distance = heading.magnitude;
    3.         var direction = heading / distance;
    4.  
    5.  
    6.         Vector3 movement = direction * Time.deltaTime * speed.Value;
    7.         agent.Move(movement);