Platformer ladders

poliver

Member
basically main problem i have is with locking character on the ladder
this is the state ive got so far to handle my ladder movement

https://gyazo.com/a9e9a8fc658f74f69447f476f326c0d6

x=other.x should be centering me but it does nothing...

Code:
    case playerStates.ladder:
       
       x = other.x;
       
       //SPRITE
       sprite_index = player_ladder;
       image_speed = 0;
       
       //KEYS DEFINED
       key_jump  =  max(keyboard_check_pressed(vk_space), gamepad_button_check_pressed(0,gp_face1));
       key_down  =  max(keyboard_check(vk_down), gamepad_button_check(0,gp_padd));
       key_up    =  max(keyboard_check(vk_up), gamepad_button_check(0,gp_padu));
       
       //MOVEMENT
       if (key_up)
       {
           image_speed = 1;
           y -= 4;
       }
       if (key_down) && !(place_meeting(x, y+4, obj_wall)) && !(place_meeting(x, y+4, object21))
       {
           image_speed = 1;
           y += 4;
       }
       if (key_jump) || !(place_meeting(x, y, object28))
           state = playerStates.normal;
       
       break;
 

Jezla

Member
The other keyword only works in a collision event or a with() statement. If this is in the step event, you'd use

Code:
x = ladder_instance.x;
with ladder_instance being the instance id of the ladder.
 
A

Anomaly

Guest
yeah all the tutorials i've found for ladders are written for GMS 1.
cant find ANY in depth ones for GMS 2
 

samspade

Member
yeah all the tutorials i've found for ladders are written for GMS 1.
cant find ANY in depth ones for GMS 2
Here is my very basic ladder code from a GMS 2. I made it so you have to jump to get off it, but that would be pretty easy to change. The x offset is because my ladder sprite's origin was 0, 0 while the character sprite was 32 x 32 and centered.

Code:
    case "CLIMBING": {
        vsp = (down - up) * move_speed;
        if (!place_meeting(x, y + vsp, obj_ladder)) vsp = 0;
        x = instance_nearest(x, y, obj_ladder).x + 16;
        if (!place_meeting(x, y, obj_ladder)) {state = "WALKING";}
        if (jump) {
            state = "JUMPING";
            vsp = jump_speed;
        }
        if (place_meeting(x, y + 1, obj_wall)) {state = "WALKING";}
        break;
    }
This code by the way is the exact same code as the player object in my enemy asset pack, so I can confirm that basically the GMS 1 and 2 code is the same.
 
Top