Skip to main content

The "collision_line_meeting" Function

Syntax#

collision_line_meeting(x1, y1, x2, y2, obj, prec, notme);
ArgumentTypeDescription
x1realThe X coordinate of the starting point of a line to check
y1realThe Y coordinate of the starting point of a line to check
x2realThe X coordinate of the ending point of a line to check
y2realThe Y coordinate of the ending point of a line to check
objobject/instanceThe object or instance to check for collisions (or Keyword all for all active instances)
precbooleanEnables or disables checking precise collision masks (if any)
notmebooleanEnables or disables excluding other instances of the running object from collision checks

Description#

Finds the exact point of collision between two sets of coordinates and an input object. Results are returned as a struct containing three keys: the nearest colliding instance id, plus the x and y values of the exact point of collision. If no collision is found, the instance ID will be considered noone and the position unchanged from x2 and y2.

The object to check for collisions can be an object ID (in which case all instances of the object will be considered, a single instance ID, or keyword all for all active instances. Set notme to true to exclude instances of the running object from consideration.

Collisions can be evaluated precisely (per-pixel, with a collision mask) or by bounding box, depending on whether prec is true or false. This setting also depends on the type of collision mask defined in the Sprite Editor (i.e. a precise mask must be created for enabling precise collisions to have any effect).

Example#

var coll = collision_line_meeting(x, y, x + mov_speed, y, obj_wall, false, true);
if (coll.id != noone) {
// Limit movement to point of collision, if any
x = coll.x;
y = coll.y;
} else {
// Otherwise move forward freely
x += mov_speed;
}