pixeltroid
Member
I thought my movement code was perfect but I just discovered that sometimes the player gets stuck a bit in walls. But not completely, as moving away from the wall "unsticks" the player. Very, very rarely getting hit by a projectile knocks me into a wall and I am unable to move. I am not able to replicate these errors whenever I will, so I am cannot pinpoint the root of the issue. These errors happens very rarely, but I am afraid that later on, other players might stumble upon these errors and think the game is broken (which it is, to an extent)
Here are the codes I have for movement and horizontal collision in the player's movement script.
Here is the code that pertains to player knockback. These are in obj_player
1. In create event
2. In step event (Forgot to post this earlier)
3. Upon colliding with enemy or enemy projectile
Is there something I can add or fix to make sure that I never get stuck in walls??
Here are the codes I have for movement and horizontal collision in the player's movement script.
Code:
{
// motion
if (move != 0) && !keyboard_check(ord("F")) && !keyboard_check(ord("S")) // if pressing in either direction
{
// accelerate
if (move == 1) hspd = min(hspd + fric, spd); // accelerate until max speed in right direction
else
if (move == -1) hspd = max(hspd - fric, -spd); // accelerate until max speed in left direction
}
else
{
// either D or A are not pressed or both are pressed at the same time -> don't move
// decelerate
if (hspd > 0) hspd = max(hspd - fric, 0); // decelerate toward 0
else
if (hspd < 0) hspd = min(hspd + fric, 0); // decelerate toward 0
}
// animation
if (move != 0)
{
image_xscale = move;
}
if (abs(hspd) > 0.50)
{
sprite_index = spr_playerwalk;
image_speed = abs(hspd) * 0.10; //.20
}
else
{
sprite_index = spr_playerstand;
image_speed = 0.10;
}
}
//horizontal collision
if (place_meeting(x+hspd, y, obj_solid))
{
while(!place_meeting(x+sign(hspd),y, obj_solid))
{
x+= sign (hspd);
}
hspd = 0;
}
x += hspd;
1. In create event
Code:
//RECOIL
recoilSpeed=10 //3;//set recoilSpeed as the speed you wish them to be flung backwards, reduce this if they recoil too fast
playerRecoil=2; //2
playerStop=-1;
directionOfBullet = ""
Code:
//RECOIL
if(playerRecoil!=-1){
playerRecoil-=1;
if (directionOfBullet == "Right"){ //facing right
hspeed-=4
vspeed-=4;
} else if (directionOfBullet == "Left"){ //facing left
hspeed+=4
vspeed -=4;
}
// speed= recoilSpeed;
playerStop=1;
}
if(playerRecoil=-1 && playerStop=1){
hspeed=0;
vspeed=0;
playerStop=-1;
}
3. Upon colliding with enemy or enemy projectile
Code:
with (obj_enemyfireball3) {
if obj_player.x <= x{
obj_player.directionOfBullet="Right";
obj_player.playerRecoil = 5
}
else {
obj_player.directionOfBullet="Left";
obj_player.playerRecoil = 5
}
}
Is there something I can add or fix to make sure that I never get stuck in walls??
Last edited: