• 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!

Problem coding ladders

luisin40

Member
Hello, I have this issue where my characters doesnt climb well the ladder object, if I stop pressing the up key he aumatically falls down and when I am pressing it, its like he is going against the wind, couldnt find a tutorial that could help me and I am kinda desperate. Thanks in advance.
GML:
create code

/// @description Initialize Player Variables


max_speed = 4;

xspeed = 0;

yspeed = 0;

acceleration = 1;

gravity_acceleration = .5;

jump_height = -9;

grab_width = 18;

jump_speed = 5;

jump_time = 0;

grav = 0.3;

//wall jumping

onwall = 0;

dust = 0;


//on_ground = false;

ladder=false

vsp = 0;


enum player {

    moving,

    ledge_grab,

    door,

    hurt,

    death,

}


/// @description controllint the player state


#region set up controls for the player

right = keyboard_check(vk_right);

left = keyboard_check(vk_left);

up = keyboard_check(vk_up);

down = keyboard_check(vk_down);

up_release = keyboard_check_released(vk_up);

#endregion


step event


#region state machine


switch(state) {

#region move state

    case player.moving:

    if (xspeed == 0) {

        sprite_index = s_player_idle;

    } else {

        sprite_index = s_player_walking;

    }

    //check if player is on the ground

    if (!place_meeting(x, y+1, o_solid)){

        yspeed += gravity_acceleration;

        

        //Player is in the air

        sprite_index = s_player_jump;

        image_index = (yspeed > 0);

        

        //control the jump height

        if (up_release and yspeed < -6) {

            yspeed = -3;

        //collision with bricks

        if place_meeting(x, y+1, o_parent_solid) {

            yspeed = 0;

            

        }

        }

    } else {

        yspeed = 0;

        //jumping code

        if (up){

            yspeed = jump_height;

            //audio_play_sound jumping sound

        }

    }

    //change direction of sprite

    if (xspeed !=0){

        image_xscale = sign(xspeed);

    }

    //check for moving left or right

    if (right or left) {

        xspeed += (right - left) * acceleration;

        xspeed = clamp(xspeed, -max_speed, max_speed);

    } else {

        apply_friction(acceleration);

    }

    

    //audio_play_sound landing

    //if (place_meeting, x, y, yspeed +1, o_solid) and yspeed >0{

    //audio_play_sound

    //}

    move(o_solid);

    

    //check for ledge grab state

    var falling = y - yprevious > 0;

    var wasnt_wall = !position_meeting(x + grab_width * image_xscale, yprevious, o_solid);

    var is_wall = position_meeting(x + grab_width * image_xscale, y, o_solid);

    

    if (falling and wasnt_wall and is_wall){

        xspeed = 0;

        yspeed = 0;

        

        //move against the ledge

        while (!place_meeting(x+image_xscale, y, o_solid)){

            x += image_xscale;

        }

        //check vertical position

        while(position_meeting(x + grab_width * image_xscale, y - 1, o_solid)){

        }

        //change sprite state

        sprite_index = s_player_ledge_grab;

        state = player.ledge_grab

        //audio_play_sound

    }

            

    //check for falling ladders

    

    if place_meeting(x + xspeed, y+yspeed, o_ladder) {

        is_on_ladder = true;

        var vertical_input = down - up;

        if vertical_input !=0{

            yspeed += vertical_input * acceleration;

            yspeed = clamp(yspeed, -(max_speed *0.75), (max_speed*0.75));

            image_speed = 1;

            sprite_index = s_player_exit;

        }

    } else {

        is_on_ladder = false;

    }
 

Nidoking

Member
You don't appear to be correcting for being on the ladder while doing all of your other movement calculations. You can't just throw ladder at the end and expect the rest of your game to fall in line. It's a system that has to be accounted for everywhere else.
 
Top