Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Can't sync Mixamo animation with Nav Mesh Agent NPC character

Discussion in 'Getting Started' started by edhalsim, Aug 1, 2023.

  1. edhalsim

    edhalsim

    Joined:
    Dec 19, 2015
    Posts:
    15
    Hi,
    My goal is to create an NPC character that turns and walks to a specified position. I've downloaded the Mixamo idle and walking animations and created a simple animator controller. When I run it, the NPC walks perfectly (flat on the ground and no sliding).

    Now, I want to get it to turn and walk towards a specified position. Here's what I tried:
    1. Created a NavMesh surface on my plane (there are no obstacles).
    2. Added a Nav Mesh Agent to my character.
    3. Disabled Apply Root Motion on the animator controller.
    4. Wrote a simple script:
    Code (CSharp):
    1. void MoveToTarget()
    2.     {
    3.         agent.SetDestination(target.position);
    4.         agent.isStopped = false;
    5.     }
    6.  
    7.     // Update is called once per frame
    8.     void Update()
    9.     {
    10.         if (target)
    11.         {
    12.             MoveToTarget();
    13.         }
    14.     }
    Now, the character floats above the nav mesh and slides along the ground as the animation walking is not in-sync with the character movement.

    Questions
    Why is it floating?
    Is this the best approach to get what I want?
    Should I even be using a nav mesh at all, or could this be done with a character controller script?

    Thanks for your time.
     
  2. edhalsim

    edhalsim

    Joined:
    Dec 19, 2015
    Posts:
    15
    I think I have it basically working. I changed it to not use nav mesh and then did the movement as follows:
    var step = _speed * Time.deltaTime; // calculate distance to move
    transform.position = Vector3.MoveTowards(transform.position, _target.position, step);