Search Unity

Question Can I have more then two parameters in blend tree ? Or how to change the direction ?

Discussion in 'Animation' started by shamenraze1988, Jul 27, 2021.

  1. shamenraze1988

    shamenraze1988

    Joined:
    Nov 24, 2020
    Posts:
    208
    This is a screenshot of my player animator controller blend tree.

    On the left bottom side there is a value name Forward :

    Forward can move between 0 and 1. If it's on 0 the player is standing still when starting to move it to the right the player will start walking slowly and when it's getting to 1 this is a natural speed.

    The problem is that it will make the player moving/walking only Forward.

    I want to be able to move the player on the same idea but also Backward. So if I will change the float between 0 and 1 it will change the speed of the player's movement but backward!



    These examples of how I'm increasing/decreasing the Forward parameter by script with a lerp:

    Code (csharp):
    1.  
    2. private IEnumerator Slowdown()
    3.    {
    4.        while(timeElapsed < lerpDuration)
    5.        {
    6.            timeElapsed += Time.deltaTime;
    7.            valueToLerp = Mathf.Lerp(startValue, endValue, timeElapsed / lerpDuration);
    8.            animator.SetFloat("Forward", valueToLerp);
    9.  
    10.            // Yield here
    11.            yield return null;
    12.        }
    13.    }
    14.  
    15.    private IEnumerator SpeedUp()
    16.    {
    17.        while(timeElapsed < lerpDuration)
    18.        {
    19.            timeElapsed += Time.deltaTime;
    20.            valueToLerp = Mathf.Lerp(endValue, startValue, timeElapsed / lerpDuration);
    21.            animator.SetFloat("Forward", valueToLerp);
    22.  
    23.            // Yield here
    24.            yield return null;
    25.        }
    26.    }
    27.  
    Then just starting one of t these coroutines.

    But what should I do and how if I want to increase/decrease a parameter in the animator controller and it will move the player Backward direction instead of forwarding?

    I'm not sure if it's possible and how to add another parameter to the Blend Tree like the Forward but Backward is not a parameter on the left but also to add it in the Blend Tree itself.