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:
And then in the script for the normal state, the conditions to change into the climb state are:
and the whole of the climb script is:
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!
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;
}
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;
}
}
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();
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!