I've been looking for a ladder tutorial but never found. So I decided to make one myself!
Also, I'll make a translation for PT-BR later.
1) Getting Started
First things first, make a simple level with Solid behavior and a player. Make it so your player can't jump on those platforms above.
I won't explain how to make a simple platformer, but you can find great
on the subject.
2) Player behaviors
Give your player a Platform and 8 direction behaviors. Simply put, we'll activate one and deactivate the other when on ladders and vice versa when not on ladders. Quite simple right?
Check the bold stuff! Those are important!
Directions: Up & Down
Set angle: No
Default Controls: Yes
I'll leave the rest on default, that's really up to you and your game.
BUT! If we leave it like this, it could get pretty buggy, so let's turn that 8 direction behavior off on the start of the layout:
It is important that you "ignore user input" instead of "set disabled".
Also, make sure you don't use the Default Controls on the Platform behavior.
Test it out, but you should be fine!
Don't forget to save! The real stuff starts here!!!
3) Ladder implementation
Let's make a new sprite object called "ladder". Make it thinner than the player.
Now let's start to implement it's functions!
Let's start by giving the player two instance variables: canClimbLadders and onLadders.
Every tick, the game will check the player's status to see if he CAN climb a ladder, setting canClimbLadders to true or false, because maybe in your game there will be some state that you won't want him to be able to climb ladders, like attacking or being hit, I don't know. In our case here, it will always be true.
The variable onLadders will simlpy tell us if the player is climbing a ladder or not.
Okay so let's make our player climb this ladder.
Test it and you can see it's working... kinda. The player only goes up when you press the Up Arrow button and it's pretty glitchy. The secret is in the first Else block.
Let's tune it up!
Okay, now we changed the condition to get out of the ladder by pressing S. We also make the player "snap" to the center of the ladder with the Set X condition. The Platformer vector conditions are there to take care of some bugs, you can find yourself if you haven't already by now.
Also, comments and SAVE IT !
By now you may have noticed that you can't raelly go up the ladder, so what's the point?
That's another simple task:
Geez, but now we can't really get off the stairs - unless we press S - but we should be able to get off the stairs when hitting the floor above or below right?
Notice that I changed the Set Platform Vector X and Set Platform Vector Y placements for optimization.
We are almost ready now! Let's just make the player climb the stairs from above it:
And - with some adjustments - we are finished :)
Hopefully the comments make reading the code and understand the logic easier.
This is my first tutorial so please try to bear with me. xD
Leave any questions (or any feedback really) in the comment section below and I'll try to answer it!
Oh and the .capx is there so be sure to download it. :)