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. Dismiss Notice

Ai agent navmesh with animation issue

Discussion in 'Scripting' started by Censureret, Mar 11, 2021.

  1. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    360
    So i have the following blend tree:

    upload_2021-3-11_20-22-23.png

    Then i have the following code:

    Code (CSharp):
    1.  
    2. Vector3 move = Target;
    3. if (move.magnitude > 1f) move.Normalize();
    4. move = transform.InverseTransformDirection(move);
    5. CheckGroundStatus();
    6. move = Vector3.ProjectOnPlane(move, m_GroundNormal);
    7. m_inputMagnitude = move.magnitude;
    8. m_TurnAmount = Mathf.Atan2(move.x, move.z);
    9. m_ForwardAmount = move.z;
    10.  
    11. m_Animator.SetFloat("Forward", m_ForwardAmount);
    12. m_Animator.SetFloat("InputMagnitude", m_inputMagnitude);
    13. m_Animator.SetFloat("Turn", m_TurnAmount);
    14.  
    This sort of work but it has a few issues when walking backward it simply swift between the "backward and strafe state"

    Can anyone help me out with how I might smooth this even more?
     
  2. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    Are you refering to smoothing the animation transition? You could smooth the values you pass into the animator by using the SetFloat version that takes a damping time and delta time. something like :

    Code (CSharp):
    1. float dampTime = .25f;
    2. m_Animator.SetFloat("Turn", m_TurnAmount, dampTime, Time.deltaTime);
     
  3. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    360
    No the problem is when he moves backwards it seems to strafe so the values are really off somehow
     
  4. Censureret

    Censureret

    Joined:
    Jan 3, 2017
    Posts:
    360