Ladder to Success! — Player Climb Ladder Animation

Kyle W. Powers
Geek Culture
Published in
5 min readJul 7, 2021

This article will show how to give the Player the ability to climb ladders. This Ladder System will be able to be used on any Ladder length and will allow the Player to go up and down the ladders.

In the Animator window for the Player, we have two bool Parameters that will control the Transition from Any State to the Ladder Climb animation and then exit the animation when the bool is false. The Climb Down animation is the Climb Up animation played in reverse.

To control the movement of the Player when climbing the Ladder, we need to add some variables.

  1. The speed at which the Player will climb the Ladder.
  2. A reference to the current Ladder that the Player is standing near.
  3. This bool will stop Player input till the Ladder has been climbed.
  4. This bool ensures that the Player is standing next to the Ladder before starting the climb.
  5. This bool is to know if the Player began at the top or bottom of the Ladder.

In Update, we add the condition that climbing Ladder must also be false for the Player input to function. Then if the Player is climbing the Ladder, we move the Controller along the Ladder depending on where they started. If the Player is climbing down, we check for when they have reached the bottom and end the climbing.

In CalculateMovement, we add the starting of the Ladder climb if the ‘E’ key is pressed and the Player is near a Ladder. On the keypress, we disable the Controller and move the Player to the z-axis position of the Ladder plus the offset for the Player. Then we set the Player to climbing the Ladder, re-enable the Controller, and start the climb animation depending on if the Player is at the bottom or top of the Ladder. Finally, we check if the Player needs to flip to face the Ladder.

This method is called from the Ladder when the Player enters or exits the Trigger. If the given bool is true, the Player is next to the Ladder, and a reference for the current Ladder is stored. Then we determine if the Player is at the top or bottom of the Ladder by seeing if the Player is higher or lower than the Ladder and set the bool accordingly. If the near Ladder bool is false, we set the Player as not next to the Ladder and clear the Ladder reference.

This method is called when the Player reaches the top or bottom of the Ladder. The method sets the Player to no longer climbing the Ladder, tells the Animator to Transition to Idle by setting the bool to false, and starts the Coroutine to move the Player to the correct end position based on where they started.

These methods let other scripts check if the Player started at the top or bottom of the Ladder and if the Player is currently climbing a Ladder.

This method is used to check which side of the Player the Ladder is on, checks if the Player is currently flipped in that direction, and returns true or false. If the Player’s z-axis position is greater than the Ladder’s, the Ladder is on the right side of the screen from the Player.

This Coroutine is called when the Player ends the Ladder climb. The method first checks if the Player is climbing down the Ladder and flips the Player. Then we disable the Controller, move the Player towards the passed in end position while the Player is farther than 0.1 from the position every frame. Once the Player is close enough to the end position, we change where the Player starts on the Ladder to the opposite of what it was and re-enable the Controller.

The Ladder has a Box Collider set to be a Trigger used to detect when the Player enters and exits, and it also has a Box Collider for the Ladder rungs so the Player can not run through the Ladder. The End Points for the Top and Bottom of the Ladder are empty GameObjects that the Player is moved towards when ending the climb.

The Ladder script needs a few variables and methods that allow other scripts to retrieve the value of those variables.

  1. The amount that the Player will be offset from the center of the Ladder when climbing.
  2. The end positions for the Player at the top and bottom of the Ladder.

When the Player enters the Trigger of the Ladder, we call the EnterExitLadder method on the PlayerController and pass in true, so the method knows the Player entered and this script for the Player to call methods from it.

If the Player exits the Trigger, we call the EnterExitLadder method on the PlayerController and pass in false, so the method knows the Player left, and this script to clear the Player’s reference. If the Ledge Grab Collider on the Player left the Trigger, we grab the PlayerController script from the parent and check if the Player is currently climbing the Ladder and if the Player started at the bottom of the Ladder. If it did, we call EndLadderClimb on the Player to move them to the top of the Ladder and end the climb.

The Player can now climb up and down the Ladder by pressing the ‘E’ key next to it.

--

--

Kyle W. Powers
Geek Culture

Unity Developer, Software Engineer, Game Developer