Nerd For Tech
Published in

Nerd For Tech

Wall Jumping in Unity

Next up, let’s see how we can figure out how to wall jump. First thing we will need to adjust is how the player reacts when jumping. As it stands now, the player can freely more direction in mid air, which physics wise makes no sense:

If order to adjust this, we will want to move our horizontal moving actions to the isGrounded method so that it will prevent us from moving while we are floating in the air:

With our movement adjusted slightly, we can see how it looks within the game:

Now that we are preventing our player from moving, let’s look at some logic behind how the player interacts with it’s surroundings a little:

With this quick debug, we can see how our player contacts the surfaces:

We can see with the blue lines that show up, the points of contact we have with the ground and the walls. From here, we have to figure out a method in which we have our play jump perpendicular t the wall on the other side:

What we are doing here is telling Unity that the new variable we have created, _wallJump is equal to the hit.normal of the contact from the wall. As for the return method, we have this in place so that unity checks to see if the conditions have changed so that it can activate walljump. With this, we can move into our jumping method and make a couple additions to give the method to wall jump:

What we are doing here is using our new _wallJump variable to be able to push ourselves off of the wall. From there, we need to give our player a little bit of height when they jump from the wall so that they can continue in an upwards trajectory:

Now that we have wall jumping in place, let’s see how we can interact with a moveable object so we can press a button to continue onwards.

--

--

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