Sprint animation play ONLY when speed = 13

So i want my sprint animation to play when holding up AND shift , and once the maxwalk speed reaches 13 , the sprint animation plays … I’ve been stuck on this for nearly 4 months now …

function Update ()
{


   if(Input.GetButtonDown("sprint"))
   {
      isSprinting = true;
      ump.animation.Play("sprintAnimation");
      movement.maxForwardSpeed = 13;
      


     
 
   }
if(Input.GetButtonUp("sprint"))
      {
          isSprinting = false;
           movement.maxForwardSpeed = 6;
           ump.animation.Stop("sprintAnimation");
           
      }


}

I know this is wrong but i’ve tried my best , Any help will be appreciated :slight_smile:

From your words, its not entirely clear to me what you want and what you currently have. Maybe you can rephrase your question, if the following is not correct:

So you want to start playing the animation “sprintAnimation” if both of the following is true:

  • The user presses the upward key
  • The user holds down shift

Also, together with starting “sprintAnimation”, you want to set the maximum speed of the avatar to “13”. (The speed is then probably used from somewhere else to actually move the character.)

Is this correct?

If so, first make sure that the following things are configured correctly:

  • You have a virtual button mapping for your key “sprint” in Edit/Project Settings/Input, which maps the main key to “right shift” and the alternative key to “left shift”
  • You have another axis mapping for your movement. Or you use the default setting of “Vertical” for that (should map to up/down arrow keys)

If that’s taken care of, change your code to not only test for the keydown/up event on “sprint” but also on the axis key.

if(Input.GetButton("sprint") && Input.GetAxis("Vertical") > 0.5f)
...
if(!Input.GetButton("sprint") || Input.GetAxis("Vertical") <= 0.5f)

Please note that I do not use GetButtonDown/Up but instead GetButton. The *Down/Up version only returns true in the one single frame when the user presses/release the corresponding key. That is undesireable for you, since your user doesn’t need to release/press the up-key and the shift-key in the same frame.