Wall Jumping in Unity
Objective: Add a Wall Jumping logic to your character in Unity.
In the first step, select a wall on the scene and add a tag of the wall to them.
Go to the player, here we need to know if our player collides with a wall surface normal, we do this using OnControllerColliderHit.
Note: This is the particular method that detects if CharacterController hits a surface normal of the object.
Now we need to make sure we only do double-jump when we hit a wall while we are not grounded and if the surface of that object has a tag of Wall.
Note: Hit normal is the line that comes out on the surface of the object perpendicular to that object.
Now we need to change logic, when we jump we don't want to change direction.
I have taken this line and put it inside the condition which checks if we are grounded so otherwise we can't move while we are not grounded.
Create a bool variable, set it to false when we are on the ground, and set it to true when we are not grounded and if we touch the wall.
In this step, we need to create a vector3 variable and assign it to the hit. normal.
Go to the else condition when we are not grounded, then check if _canDoubleJump is true and _canWallJump is false, then set the velocity equal to the surface normal times speed. But before that, I will set _yVelocity equal _wallJumpHeight, the _wall jump height is 7 float, plus I create this variable and surface normal as Vector3 global variable.
This is how I implement wall jump behavior, and tweak jump height, to get a good wall jump.