GML Jumping into Corner Causes Game to Freeze

S

SilverSlayer547

Guest
This is my first time posting on the Gamemaker Forums.
I'm working on a platformer game, and when the player jumps into a corner at some specific angles, it causes the game to freeze. This problem has only started to occur when I added jumping rotation in. I am very new to Gamemaker and I am sure that this is just an oversight in the programming. I also have some bugs in the code that I haven't worked out yet. The ones I know of so far (excluding the corner glitch) are slight rotations when landing on the ground, friction not applying when going left (working on this right now), and collisions with floors and (more frequently) walls being one pixel off. I assume removing the collision mask of the player object and using a different object as the collision mask could probably fix a few of these bugs (so that the mask doesn't rotate with the player). If there are any other oversights or improvements I could make in my code let me know. I'm always happy to learn something new.

Creation Code:
Code:
hsp = 0;
vsp = 0;
grv = 0.9;
frc = 0.2
walksp = 4;
time = 0;
image_xscale = 2;
hascontrol = true
Step Code:
Code:
//Key Input
if (hascontrol)
    {
        key_left = keyboard_check(vk_left);
        key_right = keyboard_check(vk_right);
        key_jump = keyboard_check_pressed(vk_up);
    };
    else
    {
        key_right = 0;
        key_left = 0;
        key_jump = 0;
    };
//Movement Calculation
var move = key_right - key_left;
if (!move = 0) if (move = 1) hsp = 1 * walksp; if (move = -1) hsp = -1 * walksp;; //Fixed :D
vsp = vsp + grv;
if (place_meeting(x,y + 1,obj_wall) && (key_jump))
{
    vsp = -10;
};
//Horizontal Collision + Movement
if (place_meeting(x + hsp,y,obj_wall)) {
    while (!place_meeting(x + sign(hsp),y,obj_wall)) {
        x = x + sign(hsp);
        image_angle = 0;
    };
    hsp = 0;
    image_angle = 0;
};
x = x + hsp;
//Friction Calculation
if (!hsp = 0) && (move = 0) {
    hsp = hsp - (sign(hsp) * frc);
};
if (hsp < 0.8) && (hsp > -0.8) hsp = 0;
//Vertical Collision + Movement
if (place_meeting(x,y + vsp,obj_wall)) {
    while (!place_meeting(x,y + sign(vsp),obj_wall)) {
        y = y + sign(vsp);
        image_angle = 0;
    };
    vsp = 0;
    image_angle = 0;
};
y = y + vsp;
//Animation
if (time == 1) && (sprite_index == spr_player_energy) image_speed = 0.114285714;
if (time == 1) && (sprite_index == spr_player_move_energy || sprite_index == spr_player_move) image_speed = 0.342857143;
if (!place_meeting(x,y+1,obj_wall)) && (time==0)
{
    sprite_index = spr_player;
    image_angle = image_angle + -(sign(hsp)*5);
};
else
{
    if (hsp == 0) && (time == 0)
    {
        sprite_index = spr_player;
    };
    else
    {
        if (time = 0) sprite_index = spr_player_move;
    };
};
if (!place_meeting(x,y+1,obj_wall)) && (time==1)
{
    sprite_index = spr_player_energy;
    image_angle = image_angle + -(sign(hsp)*5);
};
else
{
    if (hsp == 0) && (time == 1)
    {
        sprite_index = spr_player_energy;
    };
    else
    {
        if (time = 1) sprite_index = spr_player_move_energy;
    };
};
if (hsp != 0) image_xscale = sign(hsp) + sign(hsp);
image_yscale = 2
 
On my phone so I can't check this properly, but I would start with the while loops in your collision checking. I imagine whatever checks you are doing there are causing an infinite loop.
 
S

SilverSlayer547

Guest
On my phone so I can't check this properly, but I would start with the while loops in your collision checking. I imagine whatever checks you are doing there are causing an infinite loop.
OK. I think the reason why it's happening is because the code never had to check horizontal and vertical collision on the same block, which is what the rotation is causing it to do. I'll look and see if I can fix the bug. If I can't fix the issue then I'll use a separate object as a collision mask, to prevent the mask from rotating.
 
Top