Adjust Mecanim Animation Speed with Variable?

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.



Sorry for reviving an old question, but I was looking for a way to do this and found a better approach.

I have set up a Blend tree (2D Freeform Directional) for basic movement via parameters “HSpeed” and “VSpeed”:

 0.00, -0.01 : walking (animation speed = -1)
 0.00,  0.00 : idle
 0.00,  0.01 : walking
-0.01,  0.00 : strafe left
 0.01,  0.00 : strafe right

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
    Animator.speed = 1.0f;