Climbing Up Ladder In 2.5D Platformer Game
I had a tricky objective today: Creating the climbing up ladder behaviour in the 2.5D Platformer Game. First, I have downloaded the “Free Steel Ladder Pack” from Unity Asset Store (click here) and then placed the ladder in the scene. To detect the player, I have created a cube and got rid of it’s Mesh Renderer (or you can use a Box collider). And certainly, downloaded a climbing ladder animation clip from Mixamo.com.
Before going further, I am aware that climbing up or down from the ladder will require additional effort. So my initial plan was making the player climb up the ladder first. Just like standing on the edge, we need to set the gravity to 0 so that we do not observe a irrational gravity effect while we are on the ladder.
At my first tryout, I created a bool for the climbing behaviour and set the animation state to “Climb Ladder” once the climbing bool becomes true. To make the Player feel like he/she is actually climbing the ladder, I have added a new Climb method in the Player script which returns the Vertical input from the Player to the scene as climbing up/down. Of course, I have looped the aniation as the length of the ladder will always vary. And as expected, the Player seems like climbing even though he is standing still on the ladder, as the loop animation was checked.
I needed to find a way to make the player stand still in the position if no vertical input is gathered from the Player. So, I have thought about some alternatives and the best one seemed like manipulating the Speed variable of the Animator.
And it works!
Now, I need to find a way to move the player on the platforms above or below the ladder, according to the player’s position on the ladder. For the top part, we need a new animation clip, so I have downloaded a new one from Mixamo.
The create the trigger for the new animation, I have added another collider on the Player. Of course, with a detection collider on the Ladder.
I have tried to make these placements as good as possible in the short run, they are still not perfect but it doesn’t look so bad I think. Additionally, I have a minor bug on the animation transition, as you can observe that the player moves down just before starting the climb the top animation.
Lastly, do not forget to set the gravity to the initial value once the climb behaviour is completed and turn the Character Controller back on.