||Topic was automatically imported from the old Question2Answer platform.
I want to get a array of all physicsBody within certain range…
So that i can process them and choose the closest one.
If you know any other option to find closest physics body from player’s position
…please consider replying
There are many ways to achieve this.
The easiest being to use the area node then compare the distances of all
Can you explaine how to accomplish this
Vikrant | 2021-06-07 08:28
- Connect the
body_entered, body_exited signals of the area node
- Add/Remove bodies to an array/group
- Loop through that array or group to find the closest node
var closest = bodies
for body in bodies:
var old = closest.global_transform.origin.distance_to(global_transform.origin)
var new = body.global_transform.origin.distance_to(global_transform.origin)
if new < old:
closest = body
Wakatta | 2021-06-07 11:06
Thanks bro it helped alot
Vikrant | 2021-06-07 15:58