Question by
alex_m2000_cl · Mar 22, 2018 at 04:04 PM ·
collisioncompound collider
how detect collision with compounds colliders
Hi. i have the following question: i have the following code:
...
Collider[] hitColliders = Physics.OverlapSphere(pos, CityScale.x);
int i = 0;
Bounds c;
while (i < hitColliders.Length)
{
c = CalculateLocalBounds(obj); // obj is a GameObject with childrens each one having a collider
Debug.Log("a");
if (c.Intersects(hitColliders[i].bounds))
{
Debug.Log("i=" + i.ToString());
Debug.Break();
//if (c.gameObject!=hitColliders[i].gameObject) // i need to know if the gameobjects are differents
{
Destroy(obj);
Debug.Log("b");
}
}
i++;
}
...
the CalculateLocalBounds is:
private Bounds CalculateLocalBounds(GameObject go)
{
//Quaternion currentRotation = go.transform.rotation;
//go.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
Bounds bounds = new Bounds(go.transform.position, Vector3.zero);
///Bounds bounds = new Bounds(Vector3.zero, Vector3.zero);
foreach (Collider renderer in go.GetComponentsInChildren<Collider>())
{
if (bounds.extents == Vector3.zero)
bounds = renderer.bounds;
bounds.Encapsulate(renderer.bounds);
}
//Vector3 localCenter = bounds.center - go.transform.position;
//bounds.center = localCenter;
Debug.Log("The local bounds of this model is " + bounds);
//go.transform.rotation = currentRotation;
return bounds;
}
I want to detect if the obj with compound collider is intersecting any of the colliders detected for Physics.OverlapSphere.
any help will be very much apreciated. Thanks in advance.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612155138im_/https://answers.unity.com/themes/thub/images/avi.jpg)