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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Kotlin Interface

Things you should avoid when you use Ruby on Rails

Set up an code editor for Flutter

String Handling methods and their working behaviors

Staking Hub: New projects are getting ready to join in the fun.

Perfect strangers: 5 of the lesser-known coding languages… and why you should learn them

Predictive Modelling of a repairable system using Data Analytics Tool

Making better Architectural decisions

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
Tyler Smallwood

Tyler Smallwood

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

More from Medium

Application.Quit — Exiting the Application

Creating a Simple Cooldown System In Unity

Platformer: Player Animation Part 3

Unity : use Raycast for move the Player