Finding a GameObjects neighbors in a 3D space

I have a bunch of GameObjects in a scene. I need each GameObject to know the location and rotation of its neighbours (within a certain range). What is the best and fastest way to find the location and rotation of a GameObject’s neighbours within a certain range? Can someone provide an example? Thanks in advance!

I understand your question, but what exactly are you trying to do? A bit more context would be appreciated

2 Answers

2

Physics.SphereCast centered on the core object to get a list of objects in range, then grab these object’s transforms

Could you provide a simple example? (I am pretty new to this)

What you are looking for is :

Physics.OverLapSphere

Basically creates a sphere collider for a single frame and checks to see if it collided with anything, you would need to make the objects you are checking against have colliders, but it is also possible to give them triggers if that is not what you want to do. (Detail in the docs on how to do this).

What @JC_SummitTech said is also viable.

You are right, this would be more appropriate than a SphereCast.