Search Unity

Question Animation problem with multiples keys pressed

Discussion in 'Animation' started by XIIl_, Jul 21, 2021.

  1. XIIl_

    XIIl_

    Joined:
    Jul 21, 2021
    Posts:
    23
    Hi! I'm new here and this problem is sounding silly, but if someone can help me, please.

    The transitions are working normal, its a idle <> run that idle to the same direction of the last run.



    Both run animation go to idle if Speed parameter less than 0.01
    Bot idle animation go to run if Speed parameter greater than 0.01 and the direction decided by parameter Horizontal (-1 or 1).
    All transitions have duration 0 and Has Exit Time false

    If i press the keys individualy and release then before press another one, everything works well, but, for exemple, if i'm pressing the right arrow than press up arrow without release the right and keep changing the keys, the animation stay on the first state until i release everything.

    Here is a 30s video for better understanding (i included the Vertical parameter to be easier to see the key pressing):



    The script of this part is here:
    Code (CSharp):
    1. void Update()
    2.     {
    3.         movement.x = Input.GetAxisRaw("Horizontal") * moveSpeedHorizontal;
    4.         movement.y = Input.GetAxisRaw("Vertical") * moveSpeedVertical;
    5.  
    6.         animator.SetFloat("Horizontal", movement.x);
    7.         animator.SetFloat("Vertical", movement.y);
    8.         animator.SetFloat("Speed", movement.sqrMagnitude);
    9.     }
    10.  
    11.     private void FixedUpdate()
    12.     {
    13.         rigidbody.MovePosition(rigidbody.position + movement * Time.fixedDeltaTime);
    14.     }
    I don't know if this input axis is the right way of get this value or i'm working wrong with it.

    If someone can help me i would be thankfull!
     
  2. XIIl_

    XIIl_

    Joined:
    Jul 21, 2021
    Posts:
    23
    Ok, i created direct transitions run_right <> run_left and worked, but sounds not the best way because i will improve the movement with up and down too and looks will be a mess.

    Another solution?