Hi, I’m rebuilding my character with Mecanim, and am wondering if there is any way to adjust the speed of an animation clip with a variable (instead of a number)
For example I’d like my run animation speed to adjust based the amount of joystick axis input.
When selecting the Blend tree node in the animator view, I can set a global speed for that entire tree. Moreover, I can configure a “Speed” parameter to use as multiplier. Now I can adjust the movement speed via scripting à la animator.SetFloat("Speed").
So, if I’m interpreting this correctly and you run animation is being triggered by a “speed” variable in the animation (as is common practice). You could do something like this:
void FixedUpdate()
{
// Capture the vertical axis input
float vertInput = Input.GetAxis("Vertical");
// Set the float that triggers the run animation
// to the value of the vertical axis input
Animator.SetFloat("speed", vertInput);
// Adjust the playback speed of the animator
// when vertInput is not equal to zero
if(vertInput != 0.0f)
Animator.speed = vertInput;
// otherwise set the playback speed to 1
else
Animator.speed = 1.0f;
}