Create Idle/Walk/Run Blendtree

Hey there,

I’ m trying to setup the blendtree in mecanim for hours now. I just want a simple fade between the motions “Idle”, “Walk” and “Run”, if left shift is pressed. Currently my blendtree looks like this:

I don’t know how to set the float properly for the transition from idle to walk and then from walking to running.

Thanks for your help!

The BlendTree needs the float to be set between 0 and 1. So in your character controller script, lerp the float to 0 when Shift is not pressed, and lerp the float to 1 when shift is pressed.

Holding shift to move around is uncommon. Usually you would use Input.GetAxis or something relative like the velocity of the character to set the float. Especially for movement blendtrees that require different states, idle, walk, and run. Not sure how you plan on differentiating between walk and run, when shift can only be either pressed or not.

Maybe something like this:

Animator animator;
float speed = 0f;

// Update is called once per frame
void Update () {

    if (animator == null) animator = GetComponent<Animator>();

    if (Input.GetKey(KeyCode.LeftShift))
    {
        speed += Time.deltaTime;
    }
    else
    {
        speed -= Time.deltaTime;
    }
    speed = Mathf.Clamp(speed, 0f, 1f);

    animator.SetFloat("Speed", speed);
}

I think the tutorials explain all of this in a better way: https://unity3d.com/learn/tutorials/topics/animation