Returns the distance between the calling instance and a given point, in pixels.


GML Code Example

distance_to_point(x, y);

Argument Description
x The x position to check.
y The y position to check.

Returns: Real


This function calculates the distance from the edge of the bounding box of the calling instance to the specified x/y position in the room, with the return value being in pixels. Note that if the calling object have no sprite or no mask defined, the results will be incorrect.


GML Code Example

if distance_to_point(obj_Player.x, obj_Player.y) < range
    canshoot = true;

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

No Examples Submitted

Does this page need better examples? Be the first to Submit

These are page edits suggested by the community. Cast your vote to help improve the manual.

Suggested by /u/ohmsnap on December 13, 2016

Example code correction.

if( distance_to_point( obj_Player.x, obj_Player.y ) < range ){ canshoot = true; }

No Questions Have Been Ask

Do you have a question about this page? Ask it Here