2.5D Game Development In Unity: Physics Based Character Controller Part 2: Jumping

Gerald Clark
2 min readJul 17, 2021

In the previous article I set up the movement for the player. In this article I’ll go over setting up a jump mechanic.

To jump, the player needs to be grounded. Then I want to say if the space key is pressed the player jumps. So the following script will achieve this. This is all being handled in update for now.

Dont worry about the wall jump stuff just yet. That’ll come up a little later.

These variables help me store the info needed to accomplish jumping.

I set the yVelocity to the jumpHeight when the space key is pressed and then I set a double jump bool to true. This means I am now in the air. So now “else” if Im in the air and I press space, the player will double jump, so I’m just adding the jumpHeight to the yVelocity again.

Now I’m setting gravity. this happens in the else statement. So therefore, if the player is NOT grounded, apply gravity. The final result! Since the variables have been given the SerializeField attribute, changing the values of them i the inspector is easy. Adjust them to your liking :)

--

--

Gerald Clark

Father Game Developer Music Composer Sound Designer