place_meeting

With this function you can check a position for a collision with another instance, or all instances of an object, using the collision mask of the instance that runs the code. When you use this you are effectively asking GameMaker to move the instance to the new position, check for a collision, move back and tell you if a collision was found or not.

This will work for precise collisions, but only if both the instance and the object being checked for have precise collision masks selected. Otherwise, only bounding box collisions are applied.

In addition to objects and instances, the function also accepts:

Passing an array allows you to check for collisions against multiple objects and/or Tile Maps in one call.

If you need to get the unique instance id of the object being collided with, you should use instance_place().

Place meeting exampleSee: Collisions

 

Syntax:

place_meeting(x, y, obj);

ArgumentTypeDescription
xRealThe x position to check.
yRealThe y position to check.
objObject Asset or Object Instance or Tile Map Element ID or ArrayAn object, instance, tile map ID, keywords all/other, or array containing these items

 

Returns:

Boolean

 

Example 1:

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

The above code checks to see if there is not a collision to the left of the instance and moves the instance if there is none.

Example 2:

var _tilemap = layer_tilemap_get_id("Tiles_1");

if (keyboard_check(vk_left))
{
    if !place_meeting(x - 5, y, [obj_wall, obj_bush, _tilemap])
    {
        x -= 5;
    }
}

This is the same logic as the last example, however it uses an array to check for collisions against two types of objects (obj_wall, obj_bush) and the Tile Map for a Tile Layer called "Tiles_1".

As you only need to get your tile map ID once, you can move the first line to the Create event.