Day 94: Wall Jumping in Unity

Objective: Allow for the player to Wall Jump

Today we will allow the player to jump off walls to finish the puzzle. To start off we will need to add a new Vector3 variable called _wallJumpDirection. Next we will need a bool to know if the player can wall jump.

We will learn about a new Unity method that is used with the CharacterController. The method is called OnControllerColliderHit();

Inside the method we will check to see if the player is not grounded by using _charController.isGrounded. We will also check to see if we collided with the wall by using CompareTag.

To see the direction of the hit.point from the wall, we can use Debug.DrawRay(). It takes in the starting position of the ray, the direction of the ray and finally the color.

In the editor, you can see a blue line that represents the ray as seen below.

Now we know the direction of the ray we will assign the _wallJumpDirecton to equal the hit.normal. Then we can set _canWallJump to true.

In our original jump check we will also check for _canWallJump == false.

After the original jump section we will check for Input from the space key and if _canWallJump is true. In that section we will set _yVelocity to equal the _jumpHeight. We will also multiply the_wallJumpDirection by _playerSpeed and assign it to _velocity.

Now our player can jump off of walls!!

Thank you for reading and have a wonderful day!

I am passonate on learning to program and use Unity to become a skillful Unity Developer