- Home /
Question by
DaanSander · Jul 04, 2016 at 12:58 PM ·
c#collisioncollider
Physics#OverlapBox() does not return collision on layer
Hello, I was testing out a detection system if the player touches the collider of an object on a specific layer but when the player was colliding with the object on the layer it did not add it to the array what it collided to. When I enabled the collider of the object its Is Trigger it worked just fine. I used this code earlier in other projects but here it is not detecting it. I Checked the layerMask and it pointed to the layer it should check. I don't know why it is not detecting it could anyone help me with this?
Code:
BoxCollider box = GetComponent<BoxCollider>();
Collider[] testColliders = Physics.OverlapBox(transform.position, box.bounds.size / 2, Quaternion.Euler(new Vector3()), playerLayer);
Debug.Log("Found " + testColliders.Length + " collisions");
for (int i = 0; i < testColliders.Length; i++) {
Debug.Log("Name " + testColliders[i].gameObject.name);
}
Comment
Your answer
Follow this Question
Related Questions
Picked up objects passes through objects 2 Answers
Mesh Collider on a 2D mesh creating a 3D box? 0 Answers
Remove objects if 3 or more of them are colliding 0 Answers
OnCollisionEnter not working 1 Answer