• 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!

Collision with multiple objects

M

Machku

Guest
Hi, I'm making a 2d platformer game, and i have different objects for walls, floors and boxes. I was wondering if i have to rewrite everything i did for walls and change the oWall to oBox, or is there an easier way to do that?
Here's the code I used to make the player stop if they collide with walls:
GML:
if (place_meeting(x+hsp,y,oWall_1_1))
{
    while (!place_meeting(x+sign(hsp),y,oWall_1_1))
    {
        x = x + sign(hsp);
    }
    hsp = 0;
    
}
x += hsp * playersp;

if (place_meeting(x,y+vsp,oWall_1_1))
{
    while (!place_meeting(x,y+sign(vsp),oWall_1_1))
    {
        y = y + sign(vsp);
    }
    vsp = 0;
    
}
y += vsp;
 
Top