Wall Jump in Unity

Objective: detect when the player hits a wall and make him able to jump.

In the player script I created some variables to configure the physics of the wall jump.

Then I used the OnControllerColliderHit, check if the player is grounded and if the hitted object is a wall and if it true (that means the player is in the mid air and touched a wall) I change the _canWallJump to true, the wallJumpBoots to zero and the wallJumpDirection to hit.normal that is a Vector3 that goes to the opposite direction of the wall the player touched.

In the Update method when the player is grounded I use the SetWallJumpPhysics function to set the default values because the player is on the floor. Then when the player is nor grounded and pressed the “E” key I check if the canWallJump is true. In this case I set the canWallJump and DoubleJump to false to make the player unable to jump again, the wallJumpBoost is going to be the wallJumpDirection multiplied by the wallJumpForce and finally I set the player speed to 1 to make the player unable to move horizontally when make a wall jump.

After that I just add the wallJumpBoost to the player velocity and use the Move function to move the player.

And that’s it!!! Now the player can make a wall jump.

--

--

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