KPJ
Member
I am making a top down game in gms2, and I have an issue with collisions. I have two player sprites (Idle and Walk). The walk sprite is a bit larger than the player sprite. Both are irregular shapes (top down humans), and both their collision masks are precise (for bullet collision).
When my player collides with the wall, everything works except for two things:
1) if my player collides with the wall (let's say the wall is above me) and i am not pressing any key, it is the idle sprite, and everything works. however if i press the w (up) key, then it will change to the walk sprite (which is larger than the idle sprite and the walk sprite will get stuck in the wall so the player cannot move.
2) If I rotate my player (it follows my mouse) it's arm will get stuck in the wall, and again, it will be unable to move.
I don't think it's an issue with the code, but here it is anyway
Code:
When my player collides with the wall, everything works except for two things:
1) if my player collides with the wall (let's say the wall is above me) and i am not pressing any key, it is the idle sprite, and everything works. however if i press the w (up) key, then it will change to the walk sprite (which is larger than the idle sprite and the walk sprite will get stuck in the wall so the player cannot move.
2) If I rotate my player (it follows my mouse) it's arm will get stuck in the wall, and again, it will be unable to move.
I don't think it's an issue with the code, but here it is anyway
Code:
Code:
//Player Create Event
movespd = 2;
hspd = 0;
vspd = 0;
//Player Step Event
//Movement
upkey = -(keyboard_check(ord("W")))
leftkey = -(keyboard_check(ord("A")))
downkey = (keyboard_check(ord("S")))
rightkey = (keyboard_check(ord("D")))
horizontal = rightkey + leftkey;
vertical = upkey + downkey;
hspd = horizontal * movespd;
vspd = vertical * movespd;
//Movement & Collision
//Horizontal
if (place_meeting(x + hspd, y, oWall))
{
while(!place_meeting(x + sign(hspd), y, oWall))
{
x += sign(hspd);
}
hspd = 0;
}
x += hspd;
//Vertical
if (place_meeting(x, y + vspd, oWall))
{
while(!place_meeting(x, y + sign(vspd), oWall))
{
y += sign(vspd);
}
vspd = 0;
}
y += vspd;