Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

Nav mesh agent jitter on reaching destination

Discussion in 'Navigation' started by DarkEcho, Nov 6, 2016.

  1. DarkEcho

    DarkEcho

    Joined:
    Jul 7, 2014
    Posts:
    162
    Ello

    My nav mesh agent keeps jittering when the agent reaches the destination.

    Code (CSharp):
    1.         if (Input.GetMouseButtonDown(0))
    2.         {
    3.             if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, 100, playerLayer))
    4.             {
    5.                 Debug.DrawRay(Camera.main.ScreenPointToRay(Input.mousePosition).origin,Camera.main.ScreenPointToRay(Input.mousePosition).direction, Color.red,10f);
    6.                 agent.destination = hit.point;
    7.  
    8.             }
    9.         }
    The agent has a collider, ridged body & nav mesh agent componants

    I have replaced the raycast with a standard transform,
    removed the ridgedbody,
    tried a fresh gameobject,
    flattened the terrain.

    Im stumped, any ideas?
     
    Last edited: Nov 7, 2016
  2. JBR-games

    JBR-games

    Joined:
    Sep 26, 2012
    Posts:
    559
    Try increasing stopping distance. If its set to zero it basically never can get to the destination.
     
    hopetolive likes this.
  3. DarkEcho

    DarkEcho

    Joined:
    Jul 7, 2014
    Posts:
    162
    Didnt work, put it up to 10, 2 and 5.

    I adjusted the script to add +5 to the raycast y axis thinking the current coordinates were messing with the terrain colliders. Improvement, but after a few secs it starts jittering again...
     
  4. mattec75

    mattec75

    Joined:
    Apr 11, 2017
    Posts:
    3
    I have the same problem. Did you ever find a solution?
     
  5. affinixy

    affinixy

    Joined:
    Nov 2, 2017
    Posts:
    7
    Hi Guys, I had the same problem, and I realized that this only happens after the player with an object with a collider.

    eg: if i have a Rock, the navigation should be baked, and the player should not be colliding with this rock. But if the baking missed out the rock, and when the player touches the rock, the player's position seems to be "offset" by the collision and it will start to jitter and even rotate strangely even when he reaches the destination.



    Solution 1: My player gameobjec's rigidbody needs to be "Is Kinematic"
    Solution 2: Make sure obstacles are baked into the Navigation "walkable"

    Not sure if this is the same situation as yours.
     
    Last edited: Dec 11, 2018
    DranrebKing likes this.
  6. DranrebKing

    DranrebKing

    Joined:
    Jun 3, 2018
    Posts:
    4
    Thanks so much for this!
    Making the rigidbody "iskinematic" fixed it.