how can i make my character run and walk ?

Hi, i want to make my character move, like when i hold down “D” button he walk and when i combine it with “Shift” key he start to run. The problem here is I move my character with input.GetAxis, and inside input.getAxis we can customize the buttons like we want to use, i wonder how can I combine the “Shift” key or any key with the key that i add before in the input. getAxis so that can make my character run, and when i release he back to walk.

sorry if my english is bad, i’m beginner with unity.

Hi @Lekomese

  • For ease of use, you can use the FPS Controller from Characters by importing from Standard Assets.
  • Else you can use a “float runMultiplier” and multiply with the existing speed and if you press Shift just change the “runMultiplier” value so that it runs faster

For motion like this we normally use a “locomotion” controller, which is usually a blend tree in Animator state machine, you can simply make it so that if vertical input is greater than zero, you set anim move speed to say .5f, and then if you are holding shift, you set it to 1.0f. Then in your blend tree, blend to Run animation if speed is > .5f, blend to walk if > 0 and < .5f, and if 0 blend to Idle anim. You can also use a matrix in blend tree and add additional parameters for strafing and such. Simply to combine keys though, you can do this.

void Update()
{
    float vertical = Input.GetAxis("Vertical");
    if (vertical > 0)
    {
        if (Input.GetKey(KeyCode.LeftShift))
        {
            // running
        }
        else
        {
            //walking
        }
    }
}