Cheaply find the closest Point2D from coordinates

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By psear

I have a game in which there are various Position2D’s dotted around a map for various tasks. I need a way to identify, for example, the closest 5 to a given coordinate.

This would be done every physics frame, so a computationally cheap way of achieving this is important.

Any suggestions would be great

:bust_in_silhouette: Reply From: code

just give every position a static body with collision. nothing big just small, and the the coordinate should contain an area2d with collider of a circle. the radius should be a little big but not too big. just find bodies in the area and do your calculation based on them.

that will not take lot of space

:bust_in_silhouette: Reply From: Inces

Making everything into a body may not be that cheap. But I just got a nice idea. Wouldn’t astar2D make it faster and cheaper ? It has method to identify closest not-disabled point to given coordinate. It would allow You to write a code to repeat 5 times find closest undisabled point and make it disabled. Do You know how astar works ?