Search Unity

Question Character (humanoid) move speed differs from source animation

Discussion in 'Animation' started by Nathanieljla, Sep 25, 2022.

  1. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    I've been attempting to work around a speed issue in Unity, which led me to this simple to test, yet confusing issue. I have a walk animation that travels at 1.196 m/s. If I monitor the travel speed in game, I've discovered it's moving at 1.28 m/s. I would expect to see foot sliding at this point, but the feet look rock solid. If I attempt to force the movement vector magnitude to the correct speed, then the feet slip. I can't explain/understand how this is happening. If the animation was mapped from one character to another, then I could see it being some character height compensation, but it's the same character in the rig and animation. I'm totally lost.

    Character_speed_issue.png


    Here's my code for how I'm testing this
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class Move : MonoBehaviour
    6. {
    7.     public Animator animator;
    8.     public CharacterController characterController;
    9.     public bool useTargetParam = false;
    10.     private Vector3 _rootMotionPositionDelta = Vector3.zero;
    11.     private Quaternion _rootMotionRotationDelta = Quaternion.identity;
    12.     private float _smoothedRootSpeed = 0f;
    13.     private float _targetSpeed = 0f;
    14.     private float _outputSpeed = 0f;
    15.  
    16.  
    17.     // Update is called once per frame
    18.     void Update()
    19.     {
    20.         _smoothedRootSpeed = Mathf.Lerp(_smoothedRootSpeed, _rootMotionPositionDelta.magnitude / Time.deltaTime, 1 - Mathf.Exp(-2 * Time.deltaTime));
    21.         animator.SetFloat("Root Speed", _smoothedRootSpeed);
    22.  
    23.         Vector3 movement = !useTargetParam ? _rootMotionPositionDelta : _rootMotionPositionDelta.normalized * (_targetSpeed);
    24.         characterController.Move(movement);
    25.  
    26.         _outputSpeed = Mathf.Lerp(_outputSpeed, movement.magnitude / Time.deltaTime, 1 - Mathf.Exp(-2 * Time.deltaTime));
    27.         animator.SetFloat("Output Speed", _outputSpeed);
    28.         Reset();
    29.     }
    30.  
    31.     public void Reset()
    32.     {
    33.         //// Reset root motion deltas
    34.         _rootMotionPositionDelta = Vector3.zero;
    35.         _rootMotionRotationDelta = Quaternion.identity;
    36.         _targetSpeed = 0f;
    37.     }
    38.  
    39.  
    40.     //When this callback exists, the animator component root controller option will be overridden with a statement of
    41.     //"Handled by script".  How cool is that!
    42.     private void OnAnimatorMove()
    43.     {
    44.         _rootMotionPositionDelta += animator.deltaPosition;
    45.         _rootMotionRotationDelta = animator.deltaRotation * _rootMotionRotationDelta;
    46.         _targetSpeed += animator.GetFloat("Target Speed") * Time.deltaTime;
    47.     }
    48. }
     
  2. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    I decided to try and rule out the humanoid character as being part of the issue and it does indeed look to be part of the issue. When an animation is marked as generic the reported speed matches Maya. When I switch the rig to a humanoid it reports the animation as slower, but it still moves through space at the proper speed. Why is the humanoid reporting a different speed then playing another at runtime?

    Speed_Issue.png