- Home /
Unity detecting collision without touching
I have an object that parents an object whenever it collides with it (using OnCollisionEnter). However there can be some significant distance between the two colliders. Is there anyway to fix it so it collides when the colliders touch? Here is the relevant code.
void OnCollisionEnter(Collision collision)
{
Collider otherObject = collision.gameObject.GetComponent<Collider>();
otherObject.gameObject.transform.parent = gameObject.transform;
otherObject.enabled = false;
}
maybe clarify what you mean. it sounds like your child object is colliding with an object before it touches? - parent objects (if they have colliders also) will share collisions with children and siblings, If that's the case, you my want to create separate layers for the child collider and parent collider so they only collide with what they're intended to.
That's exactly what I mean. There's no other parent objects so I'm not sure what could be wrong. The collision will trigger before the two objects touch.
Answer by zero_null · Dec 15, 2017 at 08:27 AM
The significant distant you are talking about must not really a distant because collision is made on the basis of colliders and not renderers. . Are you sure your 3d objects colliders are exactly of the same size of the model ?