GMS 2 I can't seem to get my character to go down slopes :(

LunarTaqq

Member
I'm quite a beginner when it comes to Game Maker and mostly programming in general, so please understand if my questions are super basic. I am trying to create a platformer game. I have worked out basic movement, animation, and collision. The problem comes when I try to implement collision with slopes. I can have my character perfectly go UP slopes, but no matter what I try they always just FALL when going DOWN, they aren't actually grounded. I would love any tips/help. Thanks!

Current code for slope/wall collision:

if (place_meeting(x + hsp, y, obj_wall))
{
yplus = 0;
while (place_meeting(x + hsp, y - yplus, obj_wall)) && (yplus <= abs(1 * hsp))
{
yplus += 1;
}
if (place_meeting(x + hsp, y - yplus, obj_wall))
{
while(!place_meeting(x + sign(hsp),y,obj_wall))
{
x += sign(hsp);
}
hsp = 0;
}
else
{
y -= yplus;
}
}

x += hsp;



- LunarTaqq :)
 

gengo

Member
Heres an idea
Code:
if (place_meeting(x + hsp, y, obj_wall))
{
    yplus = 0;
    while (place_meeting(x + hsp, y - yplus, obj_wall)) && (yplus <= abs(1 * hsp))
    {
        yplus += 1;
    }
    if (place_meeting(x + hsp, y - yplus, obj_wall))
    {
        while(!place_meeting(x + sign(hsp),y,obj_wall))
        {
            x += sign(hsp);
        }
        hsp = 0;
    }
    else
    {
        y -= yplus;
    }
}
else if place_meeting(x, y + 1, obj_wall) and not place_meeting(x + hsp, y + 1, obj_wall)
{ // is on a floor rn, wouldnt be on a floor after moving
    repeat abs(hsp)
    {
        if place_meeting(x + sign(hsp), y, obj_wall) break
        if not place_meeting(x + sign(hsp), y + 1, obj_wall) and place_meeting(x + sign(hsp), y + 2, obj_wall)
        { // can move down 1px and still be on ground
            x += sign(hsp)
            y += 1
        }
        else
        {
            x += sign(hsp)
        }
    }
}
else x += hsp;
PS: Please put your code in code tag
 
Top