Luke Pierson
Member
Hey guys, decided to add a rope climbing feature to my game. So I have a rope item in the game that can be used while the player is in the ledge grab state. My issue is collision while in this state. The player will often times go too low on the rope and end up in a wall or if they try to jump off of it, they'll get stuck in the wall if the rope was too close to the wall or something. Here's the code I have for the ledge grab state:
He goes up and down the rope just fine, well besides sometimes glitching out and the player not being on the rope. The rope drop item is 2 pixels wide and 94 pixels long with origins at 1, 0. The player has a centered origin and is 16 by 16. Messing with the player's origin will likely mess up other parts of the game, whereas messing with the rope will be more helpful. Thanks for the help!
Note: The rope works pretty well most of the time, but it can be game breaking when stuck in a wall. It's also a bit weird because the last bit of code helps the collision while on a rope, but to create a rope, the player must be touching a wall (thus the ledge grab) so once the player creates a rope, they suddenly cannot move. To solve this, the player must jump off the rope and then land back on it (a mere minor issue compared to getting sucked into the walls).
Code:
if sprite_index = spr_hero || sprite_index = spr_hero_run {
sprite_index = spr_hero_ledge_grab;
}
if sprite_index = spr_hero_torch_unlit || sprite_index = spr_hero_torch_unlit_run || sprite_index = spr_hero_torch_unlit_swing {
sprite_index = spr_hero_ledge_grab_torch_unlit;
}
if sprite_index = spr_hero_torch || sprite_index = spr_hero_torch_run || sprite_index = spr_hero_torch_swing {
sprite_index = spr_hero_ledge_grab_torch;
}
var jkey = keyboard_check(vk_space);
var dkey = keyboard_check(ord('S'));
if (jkey) {
vspd = -jspd;
state = scr_move_state;
}
if (dkey) && !place_meeting(x, y, obj_rope_drop) {
state = scr_move_state;
}
if sprite_index = spr_hero_torch_hurt || sprite_index = spr_hero_hurt || sprite_index = spr_hero_torch_unlit_hurt {
y -= 1;
state = scr_move_state;
// Vertical collisions
if (place_meeting(x, y+vspd, obj_wall)) {
while (!place_meeting(x, y+sign(vspd), obj_wall)) {
y+= sign(vspd);
}
vspd = 0;
}
}
if instance_number(obj_rope_drop) < 3 {
if (keyboard_check_pressed(vk_up)) && (((inventory.rope1 = true && selector.coorleft = true) || (inventory.rope2 = true && selector.coorcenter = true) || (inventory.rope3 = true && selector.coorright = true))) {
instance_create(x, y, obj_rope_drop);
}
}
if (dkey) && place_meeting(x, y, obj_rope_drop) && !place_meeting(x, y-2, obj_wall) {
y += 1;
}
if keyboard_check(ord('W')) && place_meeting(x, y, obj_rope_drop) && !place_meeting(x, y+1, obj_wall) {
y -= 1;
}
Note: The rope works pretty well most of the time, but it can be game breaking when stuck in a wall. It's also a bit weird because the last bit of code helps the collision while on a rope, but to create a rope, the player must be touching a wall (thus the ledge grab) so once the player creates a rope, they suddenly cannot move. To solve this, the player must jump off the rope and then land back on it (a mere minor issue compared to getting sucked into the walls).