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

Nav mesh agent jitter on reaching destination

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

  1. DarkEcho

    DarkEcho

    Joined:
    Jul 7, 2014
    Posts:
    233
    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
    hunter-baun likes this.
  2. JBR-games

    JBR-games

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

    DarkEcho

    Joined:
    Jul 7, 2014
    Posts:
    233
    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:
    13
    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
  6. DranrebKing

    DranrebKing

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

    puddlepants

    Joined:
    Sep 26, 2020
    Posts:
    3
    HELL FROM 6 YEARS IN THE FUTURE. THANK YOU, HOLY S*** THIS WAS PISSSING ME OFF! stopping distance fixed for me :)
     
    hunter-baun and newtmitch like this.
  8. Gladiator-Apps

    Gladiator-Apps

    Joined:
    Jan 3, 2018
    Posts:
    3
    8 years!
     
    hunter-baun likes this.
  9. AzeFrost

    AzeFrost

    Joined:
    Jul 17, 2021
    Posts:
    55
    2022 ))
     
  10. octopus0246

    octopus0246

    Joined:
    Nov 21, 2021
    Posts:
    2
    2023 :)
     
    slambingo_ likes this.
  11. almishsubuk

    almishsubuk

    Joined:
    Jun 14, 2023
    Posts:
    1
    wow this saved my ass thanks
     
  12. Balmine

    Balmine

    Joined:
    Nov 24, 2022
    Posts:
    1
    tyty worked for me