GMS 2.3+ Collision with multiple objects

Machku

Member
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