GML Walls Won't Work

M

MrSanfrinsisco

Guest
I'm very new at coding this so this might be an obvious mistake and I apologize but I'm trying to make it so my player cannot walk outside of the room. I created a sprite for the wall which I don't think was necessary actually considering there is no picture for the wall and I created an object for the wall called "obj_wall". Maybe its as simple as the obj NEEDS a picture? I'm not too sure but here's the code I have for the player movement.
Code:
if (keyboard_check(ord("W"))) {
    if (!place_meeting(x, y-runspeed, obj_wall)) {
        y  = y - runspeed;
    }
}
if (keyboard_check(ord("A"))) {
    if (!place_meeting(x-runspeed, y,  obj_wall)) {
        x  = x - runspeed;
    }
}
if (keyboard_check(ord("S"))) {
    if (!place_meeting(x, y+runspeed, obj_wall)) {
        y  = y + runspeed;
    }
}
if (keyboard_check(ord("D"))) {
    if (!place_meeting(x+runspeed, y, obj_wall)) {
        x  = x + runspeed;
    }
}
If you need any other information just let me know and I'll gladly provide it.
 
S

Sake_v2

Guest
I'm guessing the player just walks through the walls and the collision doesn't work. Yeah, make sure the walls objects have the wall sprite assigned to them. The objects NEED a sprite for the collision check to work.
 

YoSniper

Member
The thing about place_meeting is that it has to check the collision masks of both objects.

If your wall object has no sprite, and the mask is set to <same as sprite> then the wall will have no collision mask, and place_meeting will ALWAYS return false.
 
M

MrSanfrinsisco

Guest
I'm guessing the player just walks through the walls and the collision doesn't work. Yeah, make sure the walls objects have the wall sprite assigned to them. The objects NEED a sprite for the collision check to work.
The thing about place_meeting is that it has to check the collision masks of both objects.

If your wall object has no sprite, and the mask is set to <same as sprite> then the wall will have no collision mask, and place_meeting will ALWAYS return false.
So if I create a sprite for it and set the opaque to 0 it will work?
 
S

Sake_v2

Guest
So if I create a sprite for it and set the opaque to 0 it will work?
Kind of. There is a "visible" options for objects in the objects properties in game maker. All you have to do is set assign the wall sprite to the object and uncheck the "Visible" checkbox.
 
M

MrSanfrinsisco

Guest
Kind of. There is a "visible" options for objects in the objects properties in game maker. All you have to do is set assign the wall sprite to the object and uncheck the "Visible" checkbox.
The easiest way to make invisible walls is to create a sprite of desired size, give it to an object and uncheck "Visible."

Edit: ninja'd.
That did it for me, thank you so much!!
 
Top