I intend to determine the side at which there is no neighboring GameObject (which is a hexagon tile in my case). I am using OverlapSphere function to get the array of Collider objects.
Collider[] colliderObjs = Physics.OverlapSphere(go.transform.position, 0.7f);
I can even access the position of adjacent gameobjects lying adjacent to the game object of my interest.
foreach (Collider cGO in colliderObjs){
Debug.Log(" Collider: "+cGO.transform.position);
However when I intend to find the angles at which the surrounding objects lie, I don’t get the correct results. I am using the following logic.
Vector3 dir = (obj.transform.position-current.transform.position).normalized;
float angle = Vector3.Angle(dir, trans.forward);
The first line of the above code determines the direction at which the adjacent (or collider) object is located. Obj is the adjacent object while our object of interest is current.
“trans” is the transform component of the “current” game object.
The second line of code gives the angle at which it is located.
This logic isn’t giving me correct results. Any remedies?