• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Walking on top of ladder (changing state)

tibbycat

Member
Hi, I'm relatively new(ish) is to Gamemaker and I thought I'd post here as I'm making a platform game having modified Shaun Spalding's State Machine tutorial and I'm currently stuck trying to get my player to change into the normal state when in the climbing state and reaching or landing on the top of the ladder.

As you can see in the following gif, currently when at the top of the ladder it stays in the climbing state. When pushing up it just alternates between the climbing and normal states. Upon jumping and landing back on the ladder it'll return to the climbing state (whereas I want the player to be in the normal state on top of the ladder so you can walk left and right on the top of a ladder and the walking animations from the normal states will display when doing so instead of the climbing animations).



For my code, the states are in the step event of my player object with:

Code:
//the different states
switch (state)
{
    case states.normal: scr_player_normal(); break;
    case states.climb: scr_player_climb(); break;
    case states.ledge: scr_ledge_grab_state(); break;
    case states.hurt: scr_hurt_state(); break;
}
And then in the script for the normal state, the conditions to change into the climb state are:

Code:
//climbing state change
if instance_exists(obj_climb)
{
//snap to climbing when touching it
    if ((place_meeting(x,y,obj_climb)) && (!place_meeting(x,y+1,obj_solid)) && (!key_jump_held))
    {
        hsp = 0;
        vsp = 0;
        sprite_index = spr_player_climb;
        image_speed = 0;
        state = states.climb;
    }

//snap to climbing when touching the ground
//if you're on the ground and you're pressing up
    if (place_meeting(x,y,obj_climb) && (place_meeting(x,y+1,obj_solid)) && (key_up))
    {
        hsp = 0;
        vsp = 0;
        sprite_index = spr_player_climb;
        image_speed = 0;
        state = states.climb;
    }
}
and the whole of the climb script is:

Code:
scr_getinputs();

//Ladder Movement
if(instance_place(x,y,obj_climb))
{
    if(key_up)
    {
        y -= 2;
    }
}

if(instance_place(x-1,y,obj_climb))
{
    if(key_left)
    {
        x -= 2;
    }
}

if(instance_place(x,y+8,obj_climb))
{
    if(key_down)
    {
        y += 2;
    }
}

if(instance_place(x+1,y,obj_climb))
{
    if(key_right)
    {
        x += 2;
    }
}

//animations for climbing
if ((key_up) || (key_down) || (key_left) || (key_right))
{
    sprite_index = spr_player_climb;
    image_speed = .5;
}
else
{
    image_speed = 0;
}



//Dismount wall:
if (key_jump)
{
    if(key_left)
    {
        hsp = -3;
        vsp = -3;
    }
    if(key_right)
    {
        hsp = 3;
        vsp = -3;
    }
    if(key_up)
    {
        hsp = 0;
        vsp = -3;
    }
    state = states.normal;
}

if (key_jump)
{
    vsp = -3;
    audio_play_sound(snd_jump, 10, false)
}

if (place_meeting(x,y+1,obj_solid) || (!place_meeting(x,y,obj_climb)))
{
    vsp = 0;
    state = states.normal;
}

scr_collideandmove();
Essentially I'm trying to replicate the climbing system from the 80's game Auf Wiedersehen Monty:


I'm guessing it's some small change I need to make but the logic of what exactly is escaping me. Any help anyone has is greatly appreciated!


Thanks! :)
 
O

Otacon Emmerich

Guest
let me know if this works...

Code:
//climbing state change
if instance_exists(obj_climb)
{
//snap to climbing when touching it
   if ((place_meeting(x,y,obj_climb)) && (!place_meeting(x,y+1,obj_solid) && !place_meeting(x,y+1,obj_climb)) && (!key_jump_held))
    {
        hsp = 0;
        vsp = 0;
        sprite_index = spr_player_climb;
        image_speed = 0;
        state = states.climb;
    }
 

tibbycat

Member
Ahh thanks, I tried that and it did change into the normal state at the top of the ladder but then the player falls back down as I guess the collision in the normal state is only with obj_solid and not the obj_climb:



I guess that's because there's no collision logic in my scr_collideandmove script that deals only with collisions with obj_solid:

Code:
// Horizontal collisions with solid
if (place_meeting(round(x+hsp),round(y),obj_solid))
{
    while (!place_meeting(round(x+sign(hsp)),round(y),obj_solid)) x += sign(hsp);
    hsp = 0;
}
// Move horizontally
x += hsp;

// Vertical collisions with solid
if (place_meeting(round(x),round(y+vsp),obj_solid))
{
    while (!place_meeting(round(x),round(y+sign(vsp)),obj_solid)) y += sign(vsp);
    vsp = 0;
}
// Move vertically
y += vsp;
That change also makes the player no longer snap onto the ladder when touching it mid jump too.

I think I found a clumsy solution though...

I tried putting the platform with the code from Shaun Spalding's One Way Platforms tutorial on the top of the ladder:



...and the top of the ladder then worked exactly as I wanted it to.

So then I thought, what if I made another object with the top half of the sprite of the ladder and made it a child of the one way platform?



And that's exactly how I want it to work. It's clumsy though since it's using two objects instead of one. Soo, I guess this is partially solved :p
Thanks for your help though! :)
 
T

Ting_Thing

Guest
There's several ways to do this. I'll tell you may way. Do you use jump-through platforms in your game? (That is, the kind of floor that you can pass through if you are moving up, but you will still land on it when you fall down). I have a modified jump-through platform at the top of all my ladders. The character can stand on a latter because he is actually standing on a ground item, even if that ground item is invisible. If you do this, the trick is to make it so that you can go back down the latter after you reach the top.
 

Yal

šŸ§ *penguin noises*
GMC Elder
It's clumsy though since it's using two objects instead of one. Soo, I guess this is partially solved :p
You could always make the ladders create the one-way platform on their own, if and only if there's no ladder right above them. The more you automate in your games, the less stuff you need to do manually. (I do this kind of stuff all the time)

Don't be ashamed about using more than one object for the same feature, it's almost always easier to code two small objects that do a single thing than one huge object that does tons of stuff.
 
Top