collision_point

collision_point checks the point specified by the arguments x,y for a collision with any instance of the object or tile map specified by the argument obj.

This function will return the unique id of the instance being collided with, or the Tile Map Element ID of the tile map found. If no collisions are found, noone is returned.

This check can be either precise or not, but for precise collisions to be enabled, the object or instance that you are checking for must also have precise collisions enabled for their sprite. If not, the default check is based on bounding boxes. The following image illustrates how this works:

Collision point exampleRemember, for precise collisions to be considered both the object sprite and the collision function must have precise marked as on. It should also be noted that the return value of the function can be the id of any one of the instances considered to be in collision, so if three instance overlap at that point, any one of their ids could be the return value of the function.

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.

 

Syntax:

collision_point(x, y, obj, prec, notme);

ArgumentTypeDescription
xRealThe x coordinate of the point to check.
yRealThe y coordinate of the point 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
precBooleanWhether the check is based on precise collisions (true, which is slower) or its bounding box in general (false, faster).
notmeBooleanWhether the calling instance, if relevant, should be excluded (true) or not (false).

 

Returns:

Object Instance or Tile Map Element ID or noone

 

Example:

if (collision_point(x, y, obj_Cursor, false, true) != noone)
{
    score += 10;
}

Here we are checking the point at the position of the object that has the code for the object "obj_Cursor". If there is one, then we add 10 onto the score variable.