You might have met such situations where you need to find nearest coordinate at object's edge towards a point, or find actual (non-bounding box) distance between objects, or other things of this kind. If so, you may find this example useful.

Used method is relatively simple - first find approximate distance with distance_to_point function, and then 'fix precision' by using a 'while not position_meeting' loop.

This way maximum amount of calculations will be limited to cP * iR + dP, where

cP is time needed to check object for collision against a single point

iR is instance 'radius' (maximum distance from origin to corner of bounding box)

dP is time needed to find distance between object's bounding box and point

So it should be acceptable for many cases of usage. If you need to reduce amount of calculations further, could alter distance decrementation 'rate' in two while loops. Removing while() loops entirely would give rather approximate distance calculation.

Download GMK

### Related posts: