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<GameObject> rootNodeList;
private GameObject curRoot = null;
private GameObject nextRoot = null;
void Awake()
{
rootNodeList = new List<GameObject>();
}
void Update ()
{
int val = Random.Range(0, rootNodeList.Count);
curRoot = rootNodeList[val];
if (curRoot == null) { Debug.Log("Error:current Root is Null"); }
curRoot.GetComponent<RootNode>().findLinks();
nextRoot = curRoot.GetComponent<RootNode>().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<GameObject> linkedNodes;
void Awake()
{
linkedNodes = new List<GameObject>();
}
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*.tag == "ROOTNODE")*
{
linkedNodes.Add(linkedObjects*.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];
}
Nothing is jumping out at me on this - after 14 in RootNode maybe do Debug.log(linkedObjects*.tranform.position.ToString()) to see if the bounding volumes are reporting the same t.pos*
– getyour411Thats what seems to be happening, the positions are the same and i cant figure out why its happening.
– khoatic