0 votes

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

in Engine by (273 points)

2 Answers

0 votes
Best answer

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 ?

by (7,925 points)
selected by
0 votes

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

by (189 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.