How to check two objects Collision

F

filipe

Guest
Hi i have some code that checks to see if my player is touching a wall
i have two rooms with difference walls
and i need my code to check both walls The two walls are called obj_wall and obj_stone

how do i do that?

here is my code

if keyboard_check(vk_left)
{
if !place_meeting(x - 5, y, obj_wall) x -=3;
}

if keyboard_check(vk_right)
{
if !place_meeting(x + 5, y, obj_wall) x +=3;
}

if keyboard_check(vk_down)
{
if !place_meeting(x, y+5, obj_wall) y +=3;
}

if keyboard_check(vk_up)
{
if !place_meeting(x, y-5, obj_wall) y -=3;
}
 

obscene

Member
Make a new object... par_wall.

Set par_wall to be the parent object for both obj_wall and obj_stone

Change your collision code to check for par_wall.
 
D

dj_midknight

Guest
Make a new object... par_wall.

Set par_wall to be the parent object for both obj_wall and obj_stone

Change your collision code to check for par_wall.
Seems like the smartest way to do it to me. Then you can even define more wall types and they will already be handled.
 
Top