Quantcast
Channel: Questions in topic: "loops"
Viewing all articles
Browse latest Browse all 184

Physics.OverlapSphere weirdness, not working...Sorta.

$
0
0
I have this Physics.OverlapSphere running in a loop and there are a few results I get depending on various circumstances, none of which seem to do what I am actually expecting it to do. In the event I am using var xn with the specific position, with a radius of 1 (Yes, there is absolutely an object with a collider there, I have even tried several different colliders), is simply does not find anything. If I change the radius to something like 200, it finds every single collider in the scene seemingly. If I set the location to 0,0,0 and radius to 1, it also seemingly finds every single collider in the scene... I just can't seem to get it to find the one single object in the specific location I specify with a radius of 1 (or even 1f) The objects to be found all have colliders and even show up in list when all colliders seem to be hit. Edit: also, this is in edit mode, and I do have [ExecuteInEditMode] included. I just don't get it... Please Halp!!! Thanks! private Transform myObj; private void MyFunction() { myObj = GameObject.FindWithTag("MyObjectTag").transform; foreach (Transform fooObj in myObj) { if (fooObj.name == "gametile") { //var xn = new Vector3(fooObj.transform.transform.localPosition.x - 40, 0, fooObj.transform.transform.localPosition.z); var xn = new Vector3(0, 0, 0); AdjacentTiles(xn, 1); } } } void AdjacentTiles(Vector3 center, float radius) { Collider[] colliders = Physics.OverlapSphere(center, radius); foreach (Collider collider in colliders) { Debug.Log("FOUND: " + collider.gameObject.name); } }

Viewing all articles
Browse latest Browse all 184

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>