Wall Jumping

Brennen Witzens
2 min readJan 31, 2022
Wall Jumps

Starting with Wall jumping:

Wall jumps are done when a player jumps off the wall. It pushes you away and then you jump to the next wall and then can continue to reach a ledge that you normally couldn’t.

So how is this done?

One way to do this is by using the (Player) Controller Collider hit. In this case, using the Player Controller component allows us have easy access to different parts needed for this. The OnControllerColliderHit method is called when the Player Controller component hits a collider while moving. So even when walking on the ground in this case, it is still being called. To make sure we only call it when we’re doing a wall jump, there needs to be a way to identify what a wall is. Thus the “hit.transform.CompareTag(“Wall”))” part of the if statement. Using a tag named “Wall”, set the platforms that you want as a wall to that.

Next is the jumping.

Movement for the character is done here. Grab the horizontal input, that maps it to A and D, or the Left and Right arrow keys. Then we check to see if we’re grounded or have jumped. If we’ve jumped we need a way to check to see if we’ve jumped into a wall or are touching a wall. So a bool is needed, _canWallJump. If we’ve managed to get to the wall and are hitting it then jump, we are pushed away using the hit.normal from the above method of the OnControllerColliderHit. The hit.normal is a perpendicular value to where the collider was hit. With that we set the players movement velocity to the hit.normal using the _wallVector variable, which was set when the player hit the wall. Then we set the _yVelocity to the jump strength assigned to allow for upward movement rather than falling back down right away. As to not allow the player to continuously jump after hitting the wall, setting the _canWallJump bool back to false only allowing to be true when the player hits a designated wall.

That’s wall jumping. For the next one it’ll be pushing a box onto a pressure plate.

--

--