distance_to_point

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

Syntax:

distance_to_point(x, y);


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


Returns: Real


Description

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.


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.


Back: Moving Around
Next: motion_add
© Copyright YoYo Games Ltd. 2018 All Rights Reserved