Player Jump in Unity

Make player able to jump

Rusben Guzman
2 min readJan 15, 2022

Objective: make the player jump when the space key is pressed.

In the player script I created a new variable called _jumpHeight which is the jump force for the player. In the update method we check if the player is grounded and if the space key is pressed, if it is true then we add the jump height to the velocity vector.

So now when we try the feature in play mode we can see a weird behavior, that is because immediately in the next frame the value of the velocity vector in the Y axis is reseted to 0. To fix this we have to create an auxiliary variable to store the value of the calculation in the if statement and add it to the velocity vector after the calculations.

And that’s it!!! With that change we have the correct behavior for the player jump.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.