Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

problem of the Blend Tree

Discussion in 'Scripting' started by lyokoguerier_unity, Mar 19, 2021.

  1. lyokoguerier_unity

    lyokoguerier_unity

    Joined:
    Feb 14, 2018
    Posts:
    86
    Hello to all


    I have a problem with my 3D character with

    Blendtree.PNG BlendtreeCommand.PNG Walk.PNG WalkLess.PNG


    here is the code

    Code (CSharp):
    1. [SerializeField] float speed;
    2.    Animator anim ;
    3.  
    4.  
    5. void Start () {
    6.        anim = GetComponent<Animator> ();
    7.    }
    8.  
    9.  
    10.    void Update () {
    11.  
    12.        float forward = Input.GetAxis ("Vertical");
    13.        float back = Input.GetAxis ("Vertical");
    14.        anim.SetFloat ("Walk", forward);
    15.            anim.SetFloat ("WalkBack", back);
    16.        transform.Translate (Vector3.forward * forward * speed * Time.deltaTime);
    17.        transform.Translate (Vector3.forward * back * -speed * Time.deltaTime);
    18. }
    when I make my character walk my floats are set to the same value

    Floatanimator.PNG

    which makes my character bug in the animation of the transition, I want my character to respect the direction of my two animations
     
  2. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    You are blending so you should only be using one value, such as "Walk". It would go from -1 to 1. 0 would be your 'Idle' animation, so you don't need to transition to that with a condition.
     
  3. lyokoguerier_unity

    lyokoguerier_unity

    Joined:
    Feb 14, 2018
    Posts:
    86
    I realized what you suggested, but my character is back to 0

    BlendtreeOnly.PNG

    FLoat.PNG

    he doesn't realize -1 direction when I release my Input , he doesn't respect my direction of my WalkBack animation




    Shema_Blendtree.PNG


    BlendtreeCommand2.PNG


    I have the animations of Mixamo so I invert the basic value 180 of rotation for BlendTree


    Animation.PNG
     
  4. Stardog

    Stardog

    Joined:
    Jun 28, 2010
    Posts:
    1,887
    The graph should be Blend Type: 1D using the Walk parameter.

    I don't know about the direction. You want it to turn around? It might be easier to rotate the model with code.
     
  5. lyokoguerier_unity

    lyokoguerier_unity

    Joined:
    Feb 14, 2018
    Posts:
    86
    thank you for your message

    I need 4 animation + Idle in my case, I use 2 to solve this problem gradually

    because I use a Script of Third Person Camera Controller Movement as this case if



    if you can throw me a C# example for the rotation or some specific solution
     
  6. highpockets

    highpockets

    Joined:
    Jan 17, 2013
    Posts:
    67
    I just actually stumbled across this issue. I have a very simple 1D blend tree for movement forwards and backwards. A moveSpeed float was used to control the blend. My walk backwards animation comes in at -0.05f and there are various speeds until we get to a backwards run at -1.5f, but during runtime, all backwards animations completely freeze even though the blend tree animation window was highlighting the correct motions and showing the correct moveSpeed. However, in the inspector animation preview it appeared to be fine while not in runtime.

    Anyhow, A fairly trivial fix was just to create a new blend tree for backwards motion using positive values and a flag to determine if we're in backwards mode or forwards, but this feels like I had to hack around it. Seems like Unity doesn't like the negative values in blend trees
     
    Last edited: Mar 12, 2022
    sohamxbr likes this.