How to Add a Wall-Jumping Mechanic to a Physics-Based Character Controller Using the New Unity Input System

In this article, I will go over how to implement a wall-jumping mechanic in your game in Unity. The basic jump mechanic has been a step up from my previous article.

On your player script add a new vector 3 variable called _wallNormal, the surface normal of the wall is the point that is perpendicular to the surface of the wall. This is what we will use to “push” our character in the opposite direction to the wall.

We will also add a bool to determine if the player can double jump currently.

We will call a function native to our character controller; “OnControllerColliderHit”. This will return the hit point of the collision. We first double-check to see if the player is grounded and the surface we are touching is a jumpable wall (we will set up the tags for this later). We then can store the collision point normal into our _wallNormal variable we created earlier. We can now set the _canWallJump variable to true.

This in itself is not going to do much, so in our jump function, we should wrap the double jumping and jumping section in an if statement. We want to allow normal double/jumping to occur while the player cannot double jump. However when the player can wall jump we want to reset our velocity to the _wallNormal times our speed, then set the can wall jump variable to false.

Finally, in our movement code, we can set _canWallJump to false if we are grounded.

We can set up and assign the tags to our walls next. In the inspector click on tag > add tag > + > and add your new tag. You can now assign this to your jumpable wall objects.

Now, all we have to do is to test our function.

That’s all for now.



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