What is "place_metting" mean?

Roldy

Member
if keyboard_check(vk_left)
{
if !place_meeting(x - 5, y, obj_wall) x -=5;
}
Can you explain "x-5"?
When posting code use the code formatting tool of the forum:

1623913654163.png

It makes it easier.


GML:
// If the left arrow key is down
if keyboard_check(vk_left) {            

    // Check if I dont collide with any obj_wall when I move 5 units to the left (x-5)
    if (!place_meeting(x - 5, y, obj_wall)) {
 
        // Then go ahead and actually move 5 units to the left (x -= 5)
        x -= 5;
     
    }
 
}
 
Last edited:

chamaeleon

Member
if keyboard_check(vk_left)
{
if !place_meeting(x - 5, y, obj_wall) x -=5;
}
Can you explain "x-5"?
If I (an instance) is not "place_meeting" (overlapping, roughly) an obj_wall instance if i were 5 pixels to the left of my current position, move me (an instance) 5 pixels to the left.
 
Yeah, the x - 5 is because they want to check as if the instance were sitting 5 pixels to the left. If there is no overlap (which is where the ! or not comes in, basically saying if place_meeting is NOT true), then the instance gets moved to that position: x -= 5;.

If you wanted to check exactly where the instance is (instead of 5 pixels to the left), you would omit the - 5, for example:
Code:
if !place_meeting(x,y,obj_wall) {
   // Do stuff
}
 
Top