[Solved] Climbing a ladder

0 favourites
From the Asset Store
You should help Choli to climb the mountain and reach its peak
  • Hi

    Quick question. How do I make my character climb a ladder?

    I think I know roughly the basics of how it would work??? I'm thinking when player overlaps object ladder and Up Arrow key is pressed, "Set Y to Player.Y-3".

    But this moves the player up by -3. He then drops down. I want it so for as long as the key is held down and he is overlapping the ladder, he will climb. I also want it so when the key is released he won't fall back down.

    I'm sure you have all seen it before, it's the behaviour you'll find in most platformers we have all ever played.

    Thanks in advance for your help.

  • Well, you'd have to set the gravity to 0 while you're on the ladder or else you'll fall back down. And your event should say Up Arrow is down, rather than is pressed -- "is pressed" will only make it happen once.

  • This is one way to do it:

    Perhaps give the sprite a variable called climb, then when you press Up while overlapping a ladder set the variable to 1. For another event, check if variable = 1, then set Y vector and gravity to 0. As a sub events of the variable = 1, do a check to see if player is jumping off ladder or no longer overlapping ladder (set variable to 0), then another to see if they're pressing Up/down to climb up/down.

    I made an example, its not perfect but might give you an idea:

    dl.dropbox.com/u/1024727/c2/ladderexample.capx

  • Thanks alspal, that's perfect. It would be nice if when the player reached the top of the ladder he could sit at the top rather than dropping down. Is there another event I can add to make this happen?

    And thanks for your input too Sully.

  • I decided to be a bit more helpful this time. <img src="smileys/smiley4.gif" border="0" align="middle" />

    db.tt/35AUXS8J

    I took alspal's example and added a few things: when you get to the top, it spawns an invisible solid object that lets you sit on top of the ladder. When you press down again, it destroys the object to clear the way for you to use the ladder again.

  • Perfect! Thank you both for your help. I would never have been able to work that one out for myself lol.

    It's great to find a forum with quick, worth-while support.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • No prob! The community definitely saved me when I was first starting out, so the least I can do is give back. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Sorry one last thing...

    I noticed the object created to support the player was set to a position specific to top of that one ladder.

    Is it possible to create the 'supporting' object relative to the players co-ordinates so I can have multiple instances of the same ladder. At the minute, if I create a second ladder, the position of the object created it set to appear only at the top of ladder number one.

    I hope this makes sense. I know what I want to ask, I just hope I put it into words clear enough.

  • No prob! The community definitely saved me when I was first starting out, so the least I can do is give back. <img src="smileys/smiley1.gif" border="0" align="middle" />

    And you've been doing awesome so far. Keep up the good support <img src="smileys/smiley2.gif" border="0" align="middle" />

  • Is it possible to create the 'supporting' object relative to the players co-ordinates so I can have multiple instances of the same ladder. At the minute, if I create a second ladder, the position of the object created it set to appear only at the top of ladder number one.

    Oh yeah, you can definitely do that. I updated the example to show how:

    db.tt/35AUXS8J

    There's two major changes. For one thing, in the event where you create the solid object, I added a condition to pick the correct ladder based on distance to the player. It'll pick the one you're standing on top of (unless the ladders are TOO close together -- it might be looking at the center of the ladders and which is closest, so as long as the one you're standing on has the closest center to you, it'll work).

    Anyway! The coordinates it spawns at are also changed, so they aren't hardcoded numbers anymore. Instead, it uses the coordinates of the ladder and finds the right spot from there.

    One thing the example doesn't do is let you jump from the top of one ladder to another. To fix that, you can disable the "Pick ladder" condition and add in a new one, "For each ladder". You can find that underneath "System" in the list.

    Hope that helps!

    And you've been doing awesome so far. Keep up the good support <img src="smileys/smiley2.gif" border="0" align="middle" />

    Aww, shucks. You noticed. <img src="smileys/smiley9.gif" border="0" align="middle" /> Haha, thanks a lot!

  • Thanks again for taking the time to help. I really appreciate it. This is exactly what I was I looking for. <img src="smileys/smiley4.gif" border="0" align="middle" />

  • You're quite welcome! Don't hesitate to ask if you need help on anything else. <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Funny you should say that <img src="smileys/smiley9.gif" border="0" align="middle">

    I can't quite get it to translate when I put the code into my project. The platform doesn't appear at the right place. Can you take a look please?

    For the sake of trying to line it up, I took the 'set invisible' action off so I could see what was happening.

    Here's the link:

    http://dl.dropbox.com/u/44025915/Help-Ladder.capx

    It's late here so I'm off to bed so no rush with your reply.

    Also the project is extremely messy. I've tried to tidy the events up to make it easier for you to navigate. This is literally the only project I have had since I got Construct 2. All my learning of moving platforms, enemies etc etc is in this file lol.

    Anyway...

    Thanks again.

  • Uh oh... Looks like the link you gave me is broken. <img src="smileys/smiley5.gif" border="0" align="middle" />

    Sorry that I can't have a solution waiting for you when you wake up!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)