Who wants to be a ninja? I know I do!

Objective: Being able to jump off walls in unity.

Rose Owen
4 min readJul 26, 2021

Here we can get to live out many kids' childhood fantasies and start to be a ninja! At least in the sense, we get to play as one. How are we going to do this? By giving us the ability to jump off a wall, making us able to scale up tight spaces with ease, just like a ninja.

This really can open up the possibilities for level design while adding in a fun new feature. There are a few things we want to do first though to set up the player to take action. We first need to limit the ability to be able to change our direction to only when we are on the ground, without doing this we get stuff like this.

Which we really don’t want. Doing this is really easy though, moving the update of direction and velocity into the “IsGrounded” check is all we need.

— — — — — — — — — — — -From this — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — To this— — — — — — — — — — — — — — — — — — — —

Now we can start on adding in that wall jump. First, some variables to store stuff, you know, what they do best. First a bool, this will be what restricts if we can wall jump or not. Next is a Vector3, this stores the direction of the jump, if we jump off a wall on the left it will be holding jump to the right.

Since we are using a Character Controller, we can use a method called OnControllerColliderHit, we can use this to know if we hit a wall while at the same time checking “isGrounded” to know we are off the ground. Here we can also limit what we can jump off of by adding a tag to walls we can jump off vs ones we can’t. After we know the player isn’t grounded and it’s a wall we can jump off of, we can set wall jump to true and set wall direction to what was hit’s normal, which gives us the opposite direction to jump;

Now all that is left to add is the jumping off the wall. Head down to where we aren’t grounded and we have pressed the jump button. Should look something like this.

First, we can add a check for if the wall jump is false if we do the double jump.

Next, we can add another if statement for if _wall jump is true. In it, we can set the velocity to the wall direction x speed. Set the Y velocity to jump force, like the normal double jump. Lastly, set the wall jump to false, this will make it so the player can’t just jump forever.

Only 1 more line is needed and we have everything set up and ready to test it fully out. You may have seen it already in the “isGrounded” image above. Setting the wall jump to false when is grounded.

And with that, you have graduated from Beginner Ninja Acadamy! Congrats on your new Ninja skills. See you in the next one! Who knows what you will find there.

--

--