I can't see anything wrong with the code you've sent.
What's the bigger picture?
How are you changing state?
What does your state machine look like?
What does your step event look like?
/// Control Player State
script_execute (move_state)
thats the step event...
this is the move state:
/// move_state
// Movement, Collision and Gravity
// Instance Variables
var up = (keyboard_check (ord ("W")))
var left = (keyboard_check (ord ("A")))
var down = (keyboard_check (ord ("S")))
var right = (keyboard_check (ord ("D")))
var space = (keyboard_check (vk_space))
var space_released = (keyboard_check_released (vk_space))
// Gravity
if (!place_meeting (x, y + 1, obj_wall)) {
vspd += grav;
if (space_released and vspd < -6) {
vspd = -6;
}
} else {
vspd = 0;
// Jumping Code
if (space) {
vspd = -16;
}
}
// Movement
if (right) {
hspd = spd;
}
if (left) {
hspd = -spd;
}
if (hspd !=0) {
image_xscale = sign(hspd);
}
// Friction
if (!right and !left) {
hspd = 0;
}
move (obj_wall)
// Check for ledge grab state
var height = bbox_bottom-bbox_top // get height of player
// get flags
var falling = vspd > 0 // falling
var no_wall = !place_meeting (x+image_xscale, y-height, obj_wall) // check at top of player
var is_wall = place_meeting (x+image_xscale, y, obj_wall)
if (falling and no_wall and is_wall)
{
// set speeds to 0
hspd = 0;
vspd = 0;
// Move against the ledge
while (!place_meeting (x+image_xscale, y, obj_wall))
{
x += image_xscale
}
// Make sure we are the right height
while (place_meeting (x+image_xscale, y - 30, obj_wall))
{
y-= .1;
}
state = ledge_grab_state
}
This is the ledge grab:
/// ledge_grab_state
var space_key = (keyboard_check (vk_space))
var s_key = (keyboard_check (ord ("S")))
if (s_key) {
state = move_state;
}
if (space_key) {
state= move_state
vspd= -16;
}
This is the collision:
///move (collision_object)
var collision_object = argument0
// Horizontal Collisions
if (place_meeting(x + hspd, y, obj_wall)) {
while (!place_meeting(x + sign(hspd), y, obj_wall)) {
x += sign(hspd);
}
hspd = 0;
}
x += hspd
// Vertical Collisions
if (place_meeting(x, y + vspd,obj_wall)) {
while (!place_meeting(x, y + sign(vspd), obj_wall)) {
y += sign(vspd);
}
vspd = 0;
}
y += vspd