Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Nominations have been announced for this years Unity Awards. Celebrate the wonderful projects made by your peers this year and get voting! Vote here!
    Dismiss Notice
  6. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  7. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

Pathfinding glitches rotation, then glides, then does nothing.

Discussion in 'Scripting' started by cscxfjug, Dec 8, 2018.

  1. cscxfjug


    Aug 6, 2018
    I have followed Brackey's NavMesh tutorial diligently.
    Code (CSharp):
    I have a LowMan, with following script attached:
    Code (csharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.AI;
    5. using UnityStandardAssets.Characters.ThirdPerson;
    7. public class PlayerController_X : MonoBehaviour {
    8.     public Camera cam;
    9.     public NavMeshAgent agent;
    10.     public ThirdPersonCharacter character;
    12.     void Start() {
    13.         agent.updateRotation = false;
    14.     }
    16.     void Update() {
    17.         if (Input.GetMouseButtonDown(0)) {
    18.             Ray ray = cam.ScreenPointToRay(Input.mousePosition);
    19.             RaycastHit hit;
    21.             if (Physics.Raycast(ray, out hit)) {
    22.                 agent.SetDestination(hit.point);
    23.             }
    24.         }
    27.         if (agent.remainingDistance > agent.stoppingDistance) {
    28.             character.Move(agent.desiredVelocity, false, false);
    29.         }
    30.         else {
    31.             character.Move(, false, false);
    32.         }
    33.     }
    34. }
    I attached video recording showing the situation.

    There are no errors, and as I look at Brackey's Inspector it has same items as I do.
    When I press Play, my character gets idle, as they should.
    I press my mouse button, and the character walks.
    However, as the character gets to the target.
    It starts twitching and randomly turning in a single place.
    I edited variable "Stopping Distance" and set it to 1.
    The character stopped twitching at the end of the target, however
    when near target location, it starts slipping towards the target
    without animation. So I tried editing following:

    Code (CSharp):
    2.         if (agent.remainingDistance > agent.stoppingDistance) {
    3.             character.Move(agent.desiredVelocity, false, false);
    4.         }
    5.         else {
    6.             agent.SetDestination(;
    7.             character.Move(, false, false);
    8.         }
    But that didn't fix it.

    Attached Files:

  2. hippocoder


    Digital Ape Moderator

    Apr 11, 2010
    Removed "ADHD" from title. Stick to facts on dev forums - thanks.
  3. chubbspet


    Feb 18, 2010
    Try to check if remaining distance is smaller than stopping distance, then use the "Pause" method (if I remember correctly) to pause/stop the agent. Surely it should not be needed to place those check on every frame in the main update function.