So Im trying to use Physics.OverlapSphere to get a set of objects around the object with the attached script. when testing its showing their locations to be exactly the same, I cant figure out why, please help.
/////////////////////////////////////////////////////////////////////////////
Update Class
/////////////////////////////////////////////////////////////////////////////
private List rootNodeList;
private GameObject curRoot = null;
private GameObject nextRoot = null;
void Awake()
{
rootNodeList = new List();
}
void Update ()
{
int val = Random.Range(0, rootNodeList.Count);
curRoot = rootNodeList[val];
if (curRoot == null) { Debug.Log("Error:current Root is Null"); }
curRoot.GetComponent().findLinks();
nextRoot = curRoot.GetComponent().pickNextNode();
if (nextRoot == null) { Debug.Log("Notify:current Root has no connections"); }
curVec = nextRoot.transform.position - curRoot.transform.position;
Debug.Log(nextRoot.transform.position);
Debug.Log(curRoot.transform.position);
}
/////////////////////////////////////////////////////////////////////////////
RootNode Class
/////////////////////////////////////////////////////////////////////////////
private List linkedNodes;
void Awake()
{
linkedNodes = new List();
}
public void findLinks()
{
Collider[] linkedObjects = Physics.OverlapSphere(this.transform.position, linkRadius);
Debug.Log(linkedObjects.Length);
for (int i = 0; i < linkedObjects.Length; i++)
{
if (linkedObjects[i].tag == "ROOTNODE")
{
linkedNodes.Add(linkedObjects[i].gameObject);
}
}
}
public GameObject pickNextNode()
{
int val = Random.Range(0, linkedNodes.Count);
if (linkedNodes.Count <= 0) { Debug.Log("Notify: there is no Nodes around"); }
return linkedNodes[val];
}
↧