Wall Jumping in Unity

Objective: Add logic for the Player to wall jump

The first thing we need to do is move our Vector3 variables direction and velocity from local inside the update to global variables. Then we need to make sure we can’t change direction once we have jumped so we move the direction and velocity logic inside the if is grounded so once we have jumped we can’t change the direction.

Next we need to tag the wall platforms so the scripts can identify them from the ground platforms. This way we can tell when the Player hits the wall instead of the ground so we can enable the wall jump.

We need to use the OnControllerColliderHit method using a ControllerColliderHit called hit. Inside this we run a check if the controller in grounded and hit transfrom tag is wall. We need to set a global bool for if the Player can wall jump and we need the surface normal from the wall so we create a Vector3 for wall surface normal.

Inside the OnControllerColliderHit we set the wall surface normal to the hit normal and set can wall jump to true.

We move back to the update and if the controller is grounded we set the can wall jump to false since we only need this enabled when we are in the air and hitting a wall. We then move to the else logic meaning when the Player is in the air. Here we change the logic so the if space key is pressed and can wall jump is false we check if double jump is true then before setting the jump velocity and setting the can double jump to false.

We then have an alternative if space key and wall jump is true before continuing to set the jump velocity and the Players velocity to the wall surface normal * speed. We then continue with the already implemented movement logic.

We have now split the logic of double and wall jumping. In the next post we will look at pushing objects in Unity.

--

--

--

Developer

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

Recommended from Medium

How to choose between Web|Native|Hybrid app for your #Business

Privacera’s First-Ever Apache Ranger Contest Answers and Winner

Download In ^*PDF Programming Quantum Computers: Essential Algorithms and Code Samples Read <book…

Open Source CMS in 2017 — Part 1: An Introduction to WordPress, Drupal, Grav and Ghost

CloudFormation vs TerraForm for Managing Your Site’s DNS

How to set JAVA_HOME path in Ubuntu system

Install Ngnix on EC2 server from amazone, Configurate domain, sub-domain and Cloudflare

Sabio Launches The Most Amazing Coding Bootcamp Prep Course

Sabio PreWork Summer of 2013 in Downtown LA, Four People Sitting Around A Table in A Conference Room.

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
Simon Leen

Simon Leen

Developer

More from Medium

Post Processing Primer for Unity

I think you dropped something — Creating a simple loot drop system in Unity2D

Camera Look System in Unity!

Unity : use Raycast for move the Player