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

CRODO VS Play Pad: Battle Of Launchpads

Python Dynamics Simulations: Part 4 — Sockets with C and Python

Using Clojure in Command Line with Babashka

300-times faster resolution of Finite-Difference Method using numpy

User Guide in Exploring Intro to Philosophy Dictionary & Guide to Philosophizing

No matter how big your Turo crew is, task distribution comes easily with CarSync’s multi-users

How To Build a CI/CD Pipeline for Kubernetes Stateful Applications

How To Efficiently Download Remote Directories and Files to local machine?

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

How to Create A Loading Scene in Unity

Modular Health System in Unity!

Learn to code by making a 2D space shooter game.

Quick tip — How to set up Occlusion Culling in Unity