Jump to content


Photo

Climbing Ladder


  • Please log in to reply
2 replies to this topic

#1 minthiha

minthiha

    GMC Member

  • GMC Member
  • 19 posts
  • Version:GM8

Posted 29 July 2012 - 01:49 PM

About this problem, I try many Platform Tutorial and Engine. But I didn't see what I need. I want to climb the ladder with correct position. Not beside the ladder and the edge of ladder. I want to move the player the center i.e the middle of the ladder. So, please help me about this. Like the game, Snowy Treasure Hunter.
  • 0

#2 Desert Dog

Desert Dog

    GMC Member

  • Global Moderators
  • 6409 posts
  • Version:Unknown

Posted 31 July 2012 - 11:27 AM

Accidentally posted in Tutorials, moved to Questions&Answers, and approved. Here's a bump!

This is a slightly tricky one. Basically, you'll want to 'snap' to the ladder. I might write it like this:

if keyboard_press up
if x is only 4 pixels away from the ladder x
then x= ladder x
onladder=true

so he kind of snaps to the ladder when you press up (or down). This is just a general idea of how to go about coding it.
  • 0

#3 ramses12

ramses12

    6

  • GMC Member
  • 5769 posts
  • Version:GM8.1

Posted 31 July 2012 - 11:58 AM

I'm going to leave you the task of translating Desert Dog's pseudocode to GML; as he has got you the proper answer, I'm just going to detail it a little bit
If you want to make the center of your character's sprite be aligned with the center of the ladder's sprite, you will need to set the sprites' origins to center, so a simple my x = your x could line them up perfectly. If you have a reason not to do that, you will need to make a few calculations regarding where exactly the position should be snapped.
Also, a common problem is that the calling "ladder" usually ends up with the wrong ladder, as you are generally not supposed to call for the ladder object, but instead call for an instance that represents that particular ladder that is in front of you and you want to climb. So, to recognize the ladder that you're touching, you can use a function like instance_place() - with the proper arguments, of course - or other similar functions.
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users