2.5D Platformer — Simple Walljumping #6
Jumping towards new heights
Another basic (and popular) feature in a Platformer is Walljumping. Today, I will show you how you can start implementing it in your projects.
Because Walljumping applies a force to the controller, if you set up your controller like mine that handles the movement through input rather than momentum, you won’t be able to control your controller mid-air. This can be quite frustrating as responsiveness is videogames is very important.
But because this is a mini-tutorial, I’ll only spare the information you need to walljump.
You’ll only need a Character Controller component. Using the integrated method OnControllerColliderHit, we can easily check for walls. You can do this with Raycast if you’re unsure about using this method.
For our controller, we’ll only allow walljumping if the player is not Grounded and the hit point normal angle is 90 degrees. We’ll store the normal to push the controller off the wall.
In our JumpInput method, we’ll add the WallJump functionality to make this work. Depending on the side of the wall we’re colliding, we’ll want to push off the controller from the wall with a new HorizontalSpeed and a new VerticalSpeed.