• 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 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 :)
 
G

gengo

Guest
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