The Goal - Platformer Ladders
The goal of this tutorial is to provide you with, and explain the functionality of, a simple solution for creating climbable ladders in Construct 2 for use in platformers.
Although Construct 2 provides many predefined movement functions I have yet to find one for climbing ropes and ladders, and the solutions I have found have been complex and rely on variables and multiple objects.
This solution requires two objects; the player object and the ladder, and a relatively simple event block (technically a third object is required, but this is just the player image.)
The sprites in use are free sprites provided by YoYo Games.
I want to keep this tutorial as simple as possible, so I'm going to assume knowledge about the events sheet and all the basics of making a game in Construct 2. If you've been through the first tutorial and the beginner's platformer tutorial you should be fine, though the next platformer tutorial would also be a good idea.
I'm using the free edition of Construct 2, release 132.
First things first get a room set up and create your ladder and player objects. Remember that for a platformer it is best to create a rectangle shape as your player object and pin the player image to it.
Next I gave the Player Object (the rectangle) platformer movement and set Default Movement (under Behavior>Platform in the instance properties pane) to no. This is because as standard Up makes the player jump, and we want up to move up a ladder instead. This can be amended, if you want jump to climb that can be done to, I just prefer it this way.
I have created a ladder object using an image of the bottom portion of the ladder.
I then went into the animation for the ladder and added a middle of ladder and top of ladder image as new frames:
By doing this I can make the ladder any length I like by simply changing the Initial Frame of each instance (under Animation in the instance properties pane) as needed.
This means I can make the ladder look the way I want while still being able to reference the whole thing as a single object.
I've applied my events to a separate, Controller event sheet, this way I can attach it to any level.
Firstly I added basic platform movement using the Simulate control function:
All I want here is left, right and jump. As I stated earlier you can also keep the jump function attached to the up button and have jump climb the ladder.
Next I added the climbing event block. This is a bit bigger, and makes use of the Else statement to keep it as simple as possible (to use the else statement click within the condition block and select Add...>Else, if you don't add an extra condition to the else statement it will account for all other situations)
So the block basically says this:
IF Up is pressed & Player is on Ladder
THEN Climb Ladder
IF Down is pressed & Player is on Ladder
THEN Descend Ladder
IF No button is pressed & Player is on Ladder
THEN Sit on Ladder
Reset gravity to room normal
The event makes use of the Set gravity feature, which with a platformer movement object would normally pull the object to the ground when it is off the ground. By setting the gravity to 0 we can move up and down the ladder without falling.
We need to use the final ELSE statement to reset the gravity to room normal so that the object falls as normal in any other circumstance. We could use a temporary variable but I wanted to avoid variables for this tutorial.
So we now have a working ladder function, by simply stepping away from the ladder the player will fall as normal.
I'm sure there are other methods, but this works well for me. Have you had success with other methods of ladder climbing?