Today we will learn how to make a wall-jumping behavior. We want to jump on the wall and bounce off of it.

To wall-jump we need to know when the Player hits the wall, and we need to bounce to the opposite wall.

First, create two walls and change their tag to “Wall”.

In the Player script create a new method called OnControllerColliderHit(ControllerColliderHit hit). This method is called automatically when our Character Controller hits anything. In this method we will draw a ray perpendicular to what we touch.

The conditions of wall jumping are simple: we need to be not grounded and touching a wall. We need to apply this conditions, so the ray will be draw when we meet them.

Create a new variable called _canWallJump and _wallSurfaceNormal. _canWallJump will tell us when we can jump and _wallSurfaceNormal will store the direction we want to jump when bouncing of a wall.

We will change _canWallJump to true when we hit the wall. We will also assign the _wallSurfaceNormal.

If the Character Controller is grounded we will change _canWallJump back to false.

If the Character Controller is not grounded and _canWallJump is set to false, we will double jump. If it set to true, we will add the _wallSurfaceNormal to the velocity and we will multiply this by our _speed. We will also add a jump boost.