Wall Jumping in Unity
2.5D Game Development
Objective: Make player able to wall jump
We want our player to be able to wall jump here so to set it up, create a new tag called wall and set the tag of these two walls to Wall.
Now inside the player script, define two variables one to check if wall jump and another to store the normal during the collision with the wall.
Now check if the player is on air and player is hitting the gameobject with tag ‘Wall’. IF it is true then set the wall jump to true and store the normal value to the created variable.
Now inside the else statement in the Update, create a condition when player hits the space key and the wall jump is true, store the velocity with is the normal at the hit position with the player speed. It basically stores the bouncing/reflecting value of the player. Then store the jump height to the yVelocity so that player can move upwards not down due to gravity.
Now set the wall jump to false since we don’t want the player to always wall jump after one collision with the wall. Also set the wall jump to false when in ground.
And this is the result.
Complete script here.