From the course: Advanced Unity 2D: Platformer Player Movement

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Making the player run

Making the player run - Unity Tutorial

From the course: Advanced Unity 2D: Platformer Player Movement

Start my 1-month free trial

Making the player run

- Now you may have noticed that our player is a little bit slow when he walks. Of course, we can update the speed but a better solution is to actually add a new key that'll modify the speed at which he walks and allow him to run. In order to do this, we're gonna need to open up our walk script. In here, we're gonna add a new public property that'll represent the multiplier that will use to increase the speed value when the run key is being pressed. Create a public float and call this runMultiplier. And we'll set this value to 2. This means when we're running, we'll be actually multiplying the speed by 2 and make him look like he's going faster. Next, we're gonna need to keep track if the run key is being pressed. Let's copy the left key and change this to run and set the inputState to 2, we'll add a new button later. Then, before we actually calculate the velocity X let's modify the temp speed. In this case, we're gonna want to make sure that run is actually being pressed and that the…

Contents