Legacy GM [SOLVED] Getting stuck in convex corners

S

SymbolizeLight

Guest
I tried usong shaun spalding's method of making my sprite able to jump around the platforms.

However, when the sprite jumps at an angle it sometimes perfectly hits the convex corner of a stationary platform above it. When it hits this corner, the sprite gets stuck in place until i make it move in the opposite hor direction. It looks like the sprite is hanging by its head (visually) onto the bottom corner of the platform.

Any help would be very much appreciated.

Thank you
 

TsukaYuriko

☄️
Forum Staff
Moderator
I highly doubt that a sprite is jumping - the ability to execute code is reserved for instances and creation code. :p

Anyway, if I'm imagining this correctly, it sounds like you're using a precise collision mask. Make sure that the assigned collision mask is rectangular.

If the problem persists and you don't want to rely on us imagining things, you should post the relevant code and maybe include a visualization of what is happening to make it easier (or rather at all possible) to see what might be going wrong.
 
I

immortalx

Guest
Is this the code you're using?
Code:
// horizontal
if (place_meeting(x+hsp,y,oWall))
{
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}

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

x += hsp;
y += vsp;

If so, then consider the following scenario:


At this point, the horizontal code above asks gamemaker to temporarily move the sprite to the right, as many pixels as the hsp variable. If it finds a collision there, then it moves it back to its original position and asks to move it right by 1 pixel, if there isn't a collision.
It checks all of the above for the vertical motion too. Since there are no collisions in both situations, no code in the above blocks get executed, except the last two statements which indeed move the player to the right and up.
So in the next frame the player would already be inside the wall, and the collision checks will trigger and set hsp and vsp to zero.
 
T

Ting_Thing

Guest
You could try adding a third kind of check.

Code:
// horizontal
if (place_meeting(x+hsp,y,oWall))
{
    while (!place_meeting(x+sign(hsp),y,oWall))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
}
else if (place_meeting(x,y+vsp,oWall))//vertical
{
    while (!place_meeting(x,y+sign(vsp),oWall))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
}
else if (place_meeting(x,y+vsp,oWall)) and (place_meeting(x+hsp,y,oWall))//vertical and horizontal
{
    while (!place_meeting(x+sign(hsp),y+sign(vsp),oWall))
    {
        y = y + sign(vsp);
        x = x + sign(hsp);
    }
    vsp = 0;
    vsp = 0;
}

x += hsp;
y += vsp;
I can't guarantee that will work, but I think you will want to add something like this if you wish to account for all collision possibilities.
 
Top