Player Jump in Unity

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.

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

The “Marriage” of Quality Engineering and Cybersecurity 🤵👰

How to install an SSL certificate on Alteon?

Our Investment in Hugging Face

My Journey of GSoC’21: Week 6 and Week 7

[LeetCode]#2037. Minimum Number of Moves to Seat Everyone

How enterprises like Verizon are solving the challenges of serverless adoption

Two sum

Story Points: Is finding complexity complex?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Rusben Guzman

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.

More from Medium

Creating Coin Distraction Feature in Unity (Part 1)

Creating Rewarded Video Ads in Unity

Creating a Simple Cooldown System In Unity

Designing Enemies using Abstract Classes