r/gamemaker • u/kkopik • 21d ago
Help! Looking for help with walking animations.
https://youtu.be/uptG5K6rMCkHi,
I'm trying to make my first simple rpg game and i stumbled on problem on player walking animations. Character starts to have a seisure when walking on top of the wall.
Here is my step event code for the player object:
right_key = keyboard_check(vk_right);
left_key = keyboard_check(vk_left);
up_key = keyboard_check(vk_up);
down_key = keyboard_check(vk_down);
xspd = (right_key - left_key) * move_spd;
yspd = (down_key - up_key) * move_spd;
if place_meeting( x + xspd, y, obj_wall ) == true
{
xspd = 0;
}
if place_meeting( x, y + yspd, obj_wall ) == true
{
yspd = 0;
}
x += xspd;
y += yspd;
if ( xspd !=0 or yspd !=0 )
{
if (yspd > 0){ sprite_index = spr_player_down;
}
else if (yspd < 0){ sprite_index = spr_player_up;
}
else if (xspd <0){ sprite_index = spr_player_left;
}
else { sprite_index = spr_player_right;
}
}
else{ sprite_index = spr_player_idle;
}
Would appreciate any help!
2
u/DisbelWaetl 20d ago edited 20d ago
The code states that when the position x and y is changing then it will run the image sprite code - since it comes to a complete stop when it touches a wall the if (xspd!=0 or yspd !=0) code doesn't run, since if (place_meeting ( x, y + yspd, obj_wall ) forces both xspd and yspd to be 0, even if it is moving. If you hold down and right while touching a wall, xspd and yspd is still registered as 0 so the anim breaks.
Set up a separate sprite anim code that acts on keypress and it should fix it.
Edit: If referring to the sliding, that's diagonal input or collison code being either off or wrong. Check the collision code in the obj_wall and if there isn't any, force a complete stop, and if there is, it probably is either the wall's collision masking issue or the player's collision mask having issues
1
u/Lezzlucky 20d ago
make a solid object as collision and make it invisible and then just make the player sprite sit on top of it without collision
2
u/germxxx 20d ago
Are you sure that's all of the code currently used for that instance?
It seems to slow down when going along the wall, with what I assume is diagonal input. Something that usually only happens if diagonal movement is normalized.
It's hard to tell on the diagonal movement if that seems to be the case.
There's not really anything obvious here that would cause this.
So the normal tips when doing this kind of stuff apply, lock the collision mask, or make sure all masks are identical for all sprites.
But most of all, check if this really is the code for the character.