Platformer: Ladder System

Ryan McCoach
5 min readJan 13, 2022

Intro

In this article I will go through developing a ladder climbing system. When the player is within a certain area near the ladder and presses the up arrow key, they will begin to climb. They can move up and down the ladder uses the up/down arrow keys and jump off the ladder. When the are near the top, the finish climb animation will trigger and position them on the ledge. The player will regain left and right control.

Ladder Enter

We are going to attach a game object to the player and position it in front of the player to detect when they are in range of the ladder. This game object called Ladder_Enter_Checker will have a Box Collider with Is Trigger set to true.

On the Ladder, we will attach a game object called Ladder_Enter and give it a Box Collider with Is Trigger set to true. We will also tag it “LadderEnter”.

A script will be attached to the Ladder_Enter_Checker game object and we will use the OnTriggerStay and check the game object’s tag to see if it is the “Ladder “Enter game object on the ladder. We will create a variable and store the the raw Vertical axis (up & down arrow keys). This returns either a positive 1 (up) or a negative 1 (down). So, if the vertical input is not equal to 0 (meaning either the up or down keys are being pressed, we grab the player component, so we can call the climb ladder method.

Ladder Climb

In this player method called ClimbLadder, we set the climb ladder animation to true, set the climbing ladder global variable true, and the speed animation to 0. The speed animation controls the speed at which the animation is played at and initially it will be set at 0, so it will not play but this animation will be controlled by the up/down arrow keys. The climb ladder variable set to true will enable the ladder movement.

This Ladder Movement is only called when that variable is true.

This method will get the raw vertical axis, which return -1 when moving down and 1 when move up. This is stored in a variable (verticalInput). We will use this value to create a new Vector3 where the X = 0, Y = Vertical Input value, Z = 0. This is multiple by float called climb speed that can be adjusted inn the Inspector. This new Vector3 is stored in the variable _direction and we set the player controller to Move using this direction multiplied by time.deltaTime (time between frames).

If the vertical input is not 0 (pressing the up/down arrow key), we set the animation speed to 1, which will play it and if the vertical input is 0 (not pressing the up/down key) the animation speed will be 0 which will stop the animation.

During the ladder climb if jump is pressed we turn off the climb ladder, turn on the jumping animation, trigger the jump off ladder transition to move from the climbing ladder animation to jumping animation. The Ladder Movement is disable by setting the _climbLadder to set false and we add the jump height to the Y of the direction.

Ladder Exit

On Player we already have a game object that is placed above the player that is checking for ledge grabs. We will also add a game object to the ladder called Ladder_Exit. Both has a Box Collider with Is Trigger set true.

On Ladder_Exit game object we will attach a script and will use the OnTriggerEnter to detect the Ledge_Grab_Checker, which is the game object that is attached above the player. We will get the Player component and call the LadderExit method.

This LadderExit method on the player script, will turn off the ladder climb movement by setting _climbLadder to false, turn of the climb ladder animation, trigger the animation transition to move to the exit ladder animation and we will disable the controller so there are no controls. This is important because we need the exit ladder animation to play out without the player moving during it.

The exit ladder animation has a behavior and when the animation is finished playing we grab the player component, so we can called FinishedLadderClimb from it.

This method will enable the controller, so the controls are active and we need to move the player because the animation move the model and not the controller.

This is the controller still at its original location when the exit ladder animation was played, and this is controller position being moved to match the model.

Conclusion

There is some cleaning up with this system, but the ladder can be prefabbed and reused again. The only issue is if the player moves up the ladder and back down, it is stuck in the climb animation and the only way to escape is to jump. I will explore how to fix this and post it when I figure it out.

--

--