Search Unity

Synchronyze movement and animation

Discussion in 'Navigation' started by Qwertyyy, Aug 21, 2015.

  1. Qwertyyy

    Qwertyyy

    Joined:
    Jun 10, 2015
    Posts:
    24
    Hello,

    My problem here is I have hard time syncronyzing the moment when my NPC start moving and the moving animation itself.

    I used to start the animation (by switching a boolean to true in my animator) and start the movement (by setting the destination of the navmesh agent) at the same time, but sometimes my NPC used to slide at the start since he already started to move but the transition between the current animation and the movement animation was still pending.

    I've tried to wait the walk anim start by doing this :

    Code (CSharp):
    1. private static int _walkState = Animator.StringToHash("Base Layer.Walk");
    2.  
    3.   private void move(Vector3 destination, float moveSpeed)
    4.   {
    5.       _animator.SetBool("Walk", true);
    6.       AnimatorStateInfo currentAnimState = _animator.GetCurrentAnimatorStateInfo(0);
    7.       if (currentAnimState.nameHash == _walkState)
    8.       {
    9.           _navMeshAgent.destination = destination;
    10.           _navMeshAgent.speed = moveSpeed;
    11.       }
    12.   }
    13.  
    But the 0,5 or 1 second delay before the anim start is really annoying, my NPC need to be way more reactive ...

    I also tried to increase the animation speed for the duration of the transition, but the result was really poor too.

    Is their any other way I could explore ?