Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

Vertical Jump Tutorial

Making an object or character jump in Unity is quite simple. This involves creating a C# script to add the jump functionality and enabling player input as well! So let's begin. 

First off, let's open a blank Unity project with 3D Core like this:


Once you have opened your project, we want to make a basic game object that the player (you) can interact with. So let's just use a cube for this project. In the top of your Unity project, go to GameObject -> 3D Object -> and press on Cube. You can also do the same thing by right clicking on the hierarchy. Next, we are going to give this cube a rigidbody so go to Add Component -> Rigidbody. Your project should look like this so far:


Now, we don't want the cube to just stay in space, so let's add a plane under the cube. Again, go to GameObject -> 3D Object -> Plane.  By default, it's likely overlapping the cube so all you have to do is just drag it down a bit using the move tool which is the second option from the top left of the scene tab. Perfect, now if you run play, you'll see that the cube drops and lands on the plane. However this doesn't do anything yet for our jumping mechanic. So now we want to give this cube some player input. To do that, we go to Window -> Package Manager -> make sure you are in Unity Registry -> search for Input System -> Install. After installing, the editor will tell you to restart to update the changes, so go ahead and press yes. The input system is a built in Unity package so you don't need to do anything else.


Now, after your project finishes reloading, is where we can finally start creating our jump for the cube. Unity uses C# and scripting to edit game objects, so we will make one and attach it to the cube. Click on the cube object, under the inspector go to Add component -> new script -> and give your script a name. I'll call it CubeJump. Double click on the script that was created and it should bring you to a code editor of your choice (I use Visual Studio for Mac). Write this code in your script:


In the above script, we take the jump force and multiply it by an upwards direction using Unity's AddForce method. The jump will trigger when the player presses the spacebar. This will be applied to the Rigidbody of the cube. Save the script and go back to Unity. You should see that the JumpForce is a public component in the script and you can edit the force. Right now it is 10. Press play and see how the jump feels. It's quite high right now, so let's change the jumpforce in the inspector to 5. Now it looks more like a jump. And that is it! Feel free to experiment more on your own and find the amount that you like. Thank you and I hope to see you in the next tutorial!

Support this post

Did you like this post? Tell us

Leave a comment

Log in with your itch.io account to leave a comment.