GameMaker [SOLVED]How To Check If Object Is The Nearest Distance Between 2 Objects

FoufaDjo

Member
i want to check what is the who is the nearest object between 1 & 2 to my object i though it will be like that but it didint work pls help uwu
if point_distance(x, y, o1.x, o1.y) < point_distance(x, y, o2.x, o2.y){
stuff;
}
 

Attachments

H

Homunculus

Guest
That code should work as long as you only have one instance of o1 and one instance of o2. The result is that you run "stuff" only if o1 is closer to you than o2.
 
H

Homunculus

Guest
Not really, distance_to_object takes into consideration the bounding box of the involved instances, while point_distance just uses the coordinates you pass in. If all you need is check two points, point_distance should definitely be faster.
 
Top