• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

GameMaker [SOLVED] Player or enemies get stuck when touching walls after dying

N

NickCikovic

Guest
I was testing my platform game to check for bugs and glitches in preparation for the real graphics when I encountered a very problematic glitch. If the player or an enemy touches a wall vertically AT ALL after dying, the game locks up so hard even pressing R doesn't reset it. I was following a tutorial on YouTube, confident I did everything exactly as the guy did, but it didn't help even after I looked through for probably 4 hours. I tried messing with the collision masks and points of origin of both the player/enemy and the wall itself, but that didn't work either. I need serious advice if this game is ever gonna make it to the market. The game can't freeze like that every time a dead character touches a wall. The following picture shows exactly what's going on. I can't even imagine why it's happening, but I THINK there may be an error in the Step Event code. It reads as follows. Any help is good. Thanks.
Code:
//Get Player Input


key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right) || keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);

//Calculate Movement
var move = key_right - key_left;

hsp = move * walksp;

vsp = vsp + grv;

canjump -=1;
if (canjump > 0) && (key_jump)
{
    vsp = -12;
    canjump = 0;
}

//Horizontal Collision
if (place_meeting(x+hsp,y,oWall))
{
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
        x = x sign (hsp);
    }
    hsp = 0;
}
x = x + hsp;

//Vertical Collision
if (place_meeting(x,y+vsp,oWall))
{
    while (!place_meeting(x,y+vsp,oWall))
    {
        y = y sign (vsp);
    }
    vsp = 0;
}
y = y + vsp;

//Animation
if (!place_meeting(x,y+1,oWall))
{
    sprite_index = Player;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
    
}
else
{
    canjump = 10;
    if (sprite_index == Player) audio_play_sound(snLanding,4,false);
    
    image_speed = 1;
    if (hsp == 0)
    {
        sprite_index = Player3;
    }
    else
    {
        sprite_index = Player2;
    }
}

if (hsp != 0) image_xscale = sign(hsp);
Capture.PNG
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
The type of "locking" that you describe usually stems from an infinite loop, and if it's related to your player dying then the code shown doesn't really seem relevant. We'd need to see what happens when the player dies, both in the player object and in any object that is spawned like a dead object or an effect.
 
N

NickCikovic

Guest
The type of "locking" that you describe usually stems from an infinite loop, and if it's related to your player dying then the code shown doesn't really seem relevant. We'd need to see what happens when the player dies, both in the player object and in any object that is spawned like a dead object or an effect.
Okay, and how would I do that? I apologize for being a complete noob, but I will never allow the game to be released unfinished. I’m still learning.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Well, you posted the code for the player above... what happens when they die? What changes? I do notice that in your code that you posted you use "while", and this could be the cause of the issue too. If the variable "hsp" (or "vsp") is 0 and the instance is in a collision, then the "while" will create an infinite loop, since the instance will be moving 0px out of the collision. I suspect that that's where you need to resolve the conflict actually... Should be easy enough to do. SImply change the loops to be like this:

Code:
while (!place_meeting(x,y+vsp,oWall) && vsp != 0)
    {
     y = y sign (vsp);
    }
 
N

NickCikovic

Guest
Well, you posted the code for the player above... what happens when they die? What changes? I do notice that in your code that you posted you use "while", and this could be the cause of the issue too. If the variable "hsp" (or "vsp") is 0 and the instance is in a collision, then the "while" will create an infinite loop, since the instance will be moving 0px out of the collision. I suspect that that's where you need to resolve the conflict actually... Should be easy enough to do. SImply change the loops to be like this:

Code:
while (!place_meeting(x,y+vsp,oWall) && vsp != 0)
    {
     y = y sign (vsp);
    }
I put the new code in, but that didn’t work. All I’m trying to do is get the player or enemy to slide off the vertical side of a wall.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Well, like I say, if the game freezes there is probably an infinite loop somewhere, so you have to find out where it is and then stop it. Use the debugger to work it out... run the game in debug mode, and then when it "locks up" pause the debugger and step through the code. That'll show you WHERE the issue is, and you can then work on solving it.
 
N

NickCikovic

Guest
Well, like I say, if the game freezes there is probably an infinite loop somewhere, so you have to find out where it is and then stop it. Use the debugger to work it out... run the game in debug mode, and then when it "locks up" pause the debugger and step through the code. That'll show you WHERE the issue is, and you can then work on solving it.
I did just that, and Line 10 of the code from the Step Event in oPDead turns red. The one with x = x sign (hsp);
Code:
if (done == 0)
{
    vsp = vsp + grv;

    //Horizontal Collision
    if (place_meeting(x+hsp,y,oWall))
    {
        while (!place_meeting(x+sign(hsp),y,oWall))
        {
            x = x sign (hsp);
        }
        hsp = 0;
    }
    x = x + hsp;

    //Vertical Collision
    if (place_meeting(x,y+vsp,oWall))
    {
        if (vsp >0)
        {
            done = 1;
            image_index = 1;
            alarm[0] = 60;
        }
        while (!place_meeting(x,y+vsp,oWall))
        {
            y = y sign (vsp);
        }
        vsp = 0;
    }
    y = y + vsp;
}
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Like I said, the issue is that if hsp is 0 then the instance will never move out of the collision. That's what you need to solve!
 
N

NickCikovic

Guest
Like I said, the issue is that if hsp is 0 then the instance will never move out of the collision. That's what you need to solve!
My gosh, I just figured it out. I am an idiot. I accidentally forgot the + between sign and x. It's supposed to be x = x + sign(hsp); not x = x sign (hsp); Sorry for wasting your time.
 
Top