NavPath, model twitches upon arrival, cannot fix

Updated on December 8, 2018 in [A] Tutorials
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on December 8, 2018

I have followed Brackey’s NavMesh tutorial diligently.

I have a LowMan, with following script attached:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
using UnityStandardAssets.Characters.ThirdPerson;
public class PlayerController_X : MonoBehaviour {
    public Camera cam;
    public NavMeshAgent agent;
    public ThirdPersonCharacter character;
    void Start() {
        agent.updateRotation = false;
    }
    void Update() {
        if (Input.GetMouseButtonDown(0)) {
            Ray ray = cam.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit)) {
                agent.SetDestination(hit.point);
            }
        }
        if (agent.remainingDistance > agent.stoppingDistance) {
            character.Move(agent.desiredVelocity, false, false);
        }
        else {
            character.Move(Vector3.zero, false, false);
        }
    }
}

I attached video recording showing the situation:
http://s000.tinyupload.com/index.php?file_id=90928884273141121459

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 from 0 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. It feels as if NavAgent still moves, but animation stops.
So I tried editing following:

        if (agent.remainingDistance > agent.stoppingDistance) {
            character.Move(agent.desiredVelocity, false, false);
        }
        else {
            agent.SetDestination(Vector3.zero);
            character.Move(Vector3.zero, false, false);
        }

But that didn’t fix it. How do I stop the twitching, yet not let character literally slide?

  • Liked by
Reply