Character controller wall jumping in Unity

Daniel Kirwan
4 min readJul 30, 2021

--

Objective: Allow the player to wall jump using the character controller component

Wall jumping is a great mechanic for a 2D game that allows players to get to greater heights in a level, and it looks cool.

Following on from my previous articles about the character controller component this will allow the player to wall jump using the surface normal as a direction.

A surface normal is a vector that is perpendicular to the surface you’re touching. This is given to us in a character controller method for detecting hits.

Before I jump into that method I’ll show the variables that I created for the wall jumping to work.

There are two new variables, the bool and the surfaceNormal vector. The direction and velocity are rebranding of local variables to global ones. You’ll see why in a moment.

In my PlayerMovement method I have moved the local direction and velocity vectors into an if statement from a previous article.

I decided to move the vectors in here so that the player cannot change direction when they’re wall jumping. This lead to another issue where the player was also no longer allowed to move whilst in the air. For me, platformers should always give the player the choice of movement once they have jumped. So to rectify this I added in a small if check.

If wall jump is false then the player is free to move as normal, no matter if they’re in the air or not. Now, moving on.

In the image for the isGrounded check I am turning the wallJump bool to false, this is the only place that I can make this change. The else statement to the ground check now looks like this:

The first difference here is now in the first check for the key input I am also checking if wallJumping is false. If it is then the player can double jump. If wall jump is true then I need to push the player off the wall and in the opposite direction. But how? Where do I get that direction from? It is stored in the variable wallJumpSurfaceNormal. But before I show how I’m getting that, lets finish with the jump.
I am giving the player the same jump velocity as a normal jump so that we go in an upwards direction and then giving the player some movement by * the normal by the speed of the player.

Above is a unity provided method for detecting collision for character controllers. I am checking that the player is in the air and that the object they have collided with has a tag of wall. I have tagged my wall platforms with the name of Wall.
I then set the global variable wallJumpSurfaceNormal to that of the hit.normal and set wallJump to true.

You should then end up with the result that I have. You can mess around with your settings to give different effects but I like the movement I have here.

I hope you found this article useful.

--

--

Daniel Kirwan
Daniel Kirwan

No responses yet