Unity Problem with colliding instances of same object

Posted by Kuba Sienkiewicz on Game Development See other posts from Game Development or by Kuba Sienkiewicz
Published on 2014-08-18T18:59:39Z Indexed on 2014/08/18 22:33 UTC
Read the original article Hit count: 264

Filed under:
|
|

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);
    //  }

    }
}

© Game Development or respective owner

Related posts about c#

Related posts about unity