SOLVED How to jump off of objects? (Ladders, etc.)

I'm very new to programming, and as for jumping so far, I'm able to get my character to jump on a common wall object that's below me. I've since implemented a ladder (using Shaun Spaldings tutorials) and I'm able to climb up and down it, and left and right, but haven't been able to work out jumping off of it (or onto it).

What I'm aiming for, jumping wise, is the ability to:
- jump vertically whilst on the ladder
- hold left or right whilst jumping off the ladder.
- jump onto the ladder and 'cling' onto it (I have no clue how to work this out).

-------------------------------------------------------------------

Failed Attempt - Jumping part in red below

(Changing states command from states.normal)

if (place_meeting(x, y, oLadder)) && (key_down) || (key_up)
{
hsp = 0;
vsp = 0;
state = states.ladder;
}

(states.ladder is shown)

scr_getinputs();
scr_normal_animation();
scr_collideandmove();

//Ladder Movement
hsp = 2 * (key_right - key_left); // Moving left and right
vsp = 2 * (key_down - key_up); // Moving up and down
if (key_jump)
{
vsp = -6
}

// Currently won't jump left or right at all. Pressing jump by itself causes character to instantly move up 6 frames.

// Change state back to states.normal
if (!place_meeting(x,y,oLadder))
{
hsp = 0;
vsp = 0;
state = states.normal;
}
-------------------------------------------------------------------

If anyone knows any online tutorials for this (I couldn't find anything), or could help me out, I'd be very thankful!!!! Sorry for my lack of programming knowledge :p
 
Last edited:

Yal

🐧 *penguin noises*
GMC Elder
if (key_jump)
{
vsp = -6
}
You need to also change the state back to states.normal to exit the ladder-climbing state, otherwise you're still climbing the ladder (but moving upwards at 6 pixels per step).
GML:
if (key_jump)
{
vsp = -6;
state = states.normal;
}
 
You need to also change the state back to states.normal to exit the ladder-climbing state, otherwise you're still climbing the ladder (but moving upwards at 6 pixels per step).
GML:
if (key_jump)
{
vsp = -6;
state = states.normal;
}
Hey that worked! Thank you so much.
Do you know how to jump onto the ladder and have it change to the ladder state?
 

Yal

🐧 *penguin noises*
GMC Elder
Well, this code translates to "if colliding with a ladder, and also holding either DOWN or UP, change to the ladder state and stop moving". Isn't that the same as "jumping into the ladder and change to the ladder state"...?

if (place_meeting(x, y, oLadder)) && (key_down) || (key_up)
{
hsp = 0;
vsp = 0;
state = states.ladder;
}
Also you should change the condition to this, actually. && binds tighter than || so right now, you can press up ANYWHERE and that makes you enter the ladder state, even if there's no ladder there.

if (place_meeting(x, y, oLadder)) && ((key_down) || (key_up))
 

woods

Member
if (place_meeting(x, y, oLadder)) && (key_down) || (key_up)
{
hsp = 0;
vsp = 0;
state = states.ladder;
}



does this mean..
(touching the ladder and key_down) or (key_up)
or does it mean
(touching the ladder and key_down) or (touching the ladder and key_up)



edit:
sits quietly in the corner ;o)
beat me to it
 
Well, this code translates to "if colliding with a ladder, and also holding either DOWN or UP, change to the ladder state and stop moving". Isn't that the same as "jumping into the ladder and change to the ladder state"...?



Also you should change the condition to this, actually. && binds tighter than || so right now, you can press up ANYWHERE and that makes you enter the ladder state, even if there's no ladder there.

if (place_meeting(x, y, oLadder)) && ((key_down) || (key_up))
Thanks for that slight change! I implemented that.

"Isn't that the same as "jumping into the ladder and change to the ladder state"...?"
Not really. Atm I have to press either UP or DOWN while on the ladder to change the state. What I would like to do is also have the player jump from away from the ladder, land on it, and change to the ladder state if that makes sense?
 
Thanks for that slight change! I implemented that.

"Isn't that the same as "jumping into the ladder and change to the ladder state"...?"
Not really. Atm I have to press either UP or DOWN while on the ladder to change the state. What I would like to do is also have the player jump from away from the ladder, land on it, and change to the ladder state if that makes sense?
Oops! I should mention that (key_jump) is used for spacebar and is different from (key_up)!
 

Yal

🐧 *penguin noises*
GMC Elder
gh
What I would like to do is also have the player jump from away from the ladder, land on it, and change to the ladder state if that makes sense?
[/QUOTE]
It makes sense, but it's going to be more complicated to code.
  • You instantly touch the ladder again after jumping off of it (unless you jump off it at the very edge of the ladder so you can move off it in 1 frame of gameplay), so you'd instantly land on it again (and start climbing it again) without some way to stop you from doing that.
  • with a way to stop you from reclimbing the ladder, you get new issues, because now the player might reclimb the ladder when they mean not to, and also fail to reclimb the ladder when they mean to (because the cooldown still prevents reclimbing)
The best way to deal with these issues I can think of, is to have "left / right side ladders" instead of the classic "background ladders"... aka, the ladders are |: shapes on the left/right side of platforms, instead of # shapes in the background, and when the player jumps off them they get launched in the other direction with enough speed that it's impossible to accidentally collide with them again. And then just change the condition like so:
  • if there's a collision left with a |: ladder, and the player is holding LEFT, change to "left climb" state
  • If there's a collision right with a :| ladder, and the player is holding RIGHT, change to "right climb" state
  • the two climbing states only differ in which direction you jump off the ladder, and otherwise has the exact same code (which you should put in a script to avoid having to duplicate code)
 

Paskaler

Member
You could also try to implement some sort of flag, eg. just_left_ladder, which you would set to true when jumping of the ladder, and only allow switching to state.ladder if this variable is false. And, after this variable is set to true, start an alarm as well, which, on completion sets it back to false.

From the code Yal posted above:

GML:
if (key_jump && !just_left_ladder)
{
    vsp = -6;
    state = states.normal;
   
    just_left_ladder = true;
    alarm[0] = room_speed / 2; // half a second
}
And in the Alarm 0 event:

GML:
just_left_ladder = false;
Doing it this way, you'd have to also add the check for the just_left_ladder variable elsewhere in your code where you're switching into state.ladder.
 
Top