Syncing animations with movement speed changes.

nRedux

Member
I tweaked the ground damping setting in the UltimateCharacterLocomotion script to a lower speed and saw that animations don't by default correlate with move speed dynamically. Was wondering what the suggested approach to handling movement speed adjustments is so it's not a constant effort to keep things in sync.
 
The animations are based on the forward/horizontal input values which don't factor in the actual velocity. One way to handle this would be to create a new ability that sets the float value parameter which could be based on the forward velocity.
 
The animations are based on the forward/horizontal input values which don't factor in the actual velocity. One way to handle this would be to create a new ability that sets the float value parameter which could be based on the forward velocity.

"sets the float value parameter" Are you referring to setting HorizontalMovement and FowardMovement myself, or are you suggesting I create add parameters to the animator controller which are driven by this hypothetical ability? I'm guessing the latter.

Thanks for being so consistently responsive to queries.
 
I thought I'd try something fairly simple which was to simply have the Ultimate Character Locomotion component motor setup to user root motion. I saw there was a Root Motion Speed Multiplier field which could be modified. I then thought I'd be clever and simply apply that value but my guess is that value is just used in the unity root motion callbacks to modify the movement applied from the root motion.

C#:
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character;

public class SyncMoveAnimation : Ability
{

    [SerializeField]
    float referenceSpeed;

    private Animator animator = null;
    private UltimateCharacterLocomotion locomotion = null;


    public override void Awake()
    {
        animator = GetComponent<Animator>();
        locomotion = GetComponent<UltimateCharacterLocomotion>();
    }

    public override void Update()
    {
        animator.SetFloat("AnimationSpeed", locomotion.RootMotionSpeedMultiplier);
        base.Update();
    }
}

As a result I just change it to utilize the referenceSpeed member I'd ignored originally.


Code:
using UnityEngine;
using Opsive.UltimateCharacterController.Character.Abilities;
using Opsive.UltimateCharacterController.Character;

public class SyncMoveAnimation : Ability
{

    [SerializeField]
    float referenceSpeed = 1;

    private Animator animator = null;
    private UltimateCharacterLocomotion locomotion = null;


    public override void Awake()
    {
        animator = GetComponent<Animator>();
        locomotion = GetComponent<UltimateCharacterLocomotion>();
    }

    public override void Update()
    {
        animator.SetFloat("AnimationSpeed", referenceSpeed);
        base.Update();
    }
}

Have you considered adding such animation rate adjustments/syncing into the controller somewhere? It seems like it'd be commonly needed. This leads me to wonder if I'm looking at this wrong. This works as expected if a person is looking for simple movement speed control.
 
In most cases if you want the animation to match the speed you can use root motion. This will allow the character to move at the exact same rate as the animation.

If you really do not want to use root motion though then you'll need to set the AbilityFloatData parameter with a new ability that is based on the velocity. There isn't an AnimationSpeed parameter but you can set the AbilityFloatData parameter within the UpdateAnimator callback, similar to how Jump sets this parameter to the vertical velocity:

Code:
                SetAbilityFloatDataParameter(m_CharacterLocomotion.LocalLocomotionVelocity.y);
 
Top