1
\$\begingroup\$

I want to check if object's instance is overlapping with another instance (any spawned object with another spawned object, not necessary the same object). I'm doing this by detecting collisions between bodies. But I have a problem. Spawned object (instances) are detecting collision with everything but other spawned objects. I've checked collision layers etc. All of spawned objects have rigidbodies and mesh colliders. Also when I attach my script to another body and I touch that body with an instanced object it detects collision. So problem is visible only in collision between spawned objects. And one more information I have script, rigid body and collider attached to child of main object.

    using UnityEngine;
using System.Collections;

public class CantPlace : MonoBehaviour {

    public bool collided = false;
    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {
        //Debug.Log (collided);
    }

    void OnTriggerEnter(Collider collider) {
                //if (true) {
                        //foreach (Transform child in this.transform) {
                        //              if (child.name == "Cylinder") {


                                //collided = true;
                                Color c;
                                c = this.renderer.material.color;
                                c.g = 0f;
                                c.b = 1f;
                                c.r = 0f;
                                this.renderer.material.color = c;
                                Debug.Log (collider.name);
                        //}
            //  }
                //}

        //foreach (ContactPoint contact in collision.contacts) {
    //      Debug.DrawRay(contact.point, contact.normal, Color.red,15f);
    //  }

    }
}
\$\endgroup\$
  • 1
    \$\begingroup\$ Are the mesh colliders convex and marked as such in the inspector? Mesh collision checks are more expensive, so Unity only checks mesh colliders against each other if at least one of them is marked convex. \$\endgroup\$ – rutter Aug 18 '14 at 20:33
1
\$\begingroup\$

Turning on convex mesh fixed the problem. I have done it by script, because after importing object from blender there is no check box allownig to do this.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.