distance_to_object

This function calculates the distance from the edge of the bounding box of the calling instance to the nearest edge of the nearest instance of the object specified. The object can be an object index or a specific instance ID as well as the keyword other, and the distance is returned in pixels. Note that if either of the objects have no sprite or no mask defined, the results will be incorrect.

 

Syntax:

distance_to_object(obj);

ArgumentTypeDescription
objObject Asset or Object InstanceThe object to check for.

 

Returns:

Real

 

Example:

if (distance_to_object(obj_Player) < range)
{
    canshoot = true;
}

The above code will check for the distance to the player object and if it is less than the value stored in the variable "range" the variable "canshoot" is set to true.