- Home /
collision detection on child rigidbodies
Hello!
I have an object which is rigidbody and has multiple children that are, too, rigidbodies. I would like to detect collisions (which happened on either the children or the parent object) in the parent. What is the common way to do it?
Answer by Berenger · Feb 04, 2012 at 04:33 PM
First, you can't detect a collision on a rigidbody : you detect it on the Collider. Subtle difference yet important.
Then, to detect a collision on a collider, ou to attach a script on that object with a Collision Event call back, like OnCollisionEnter /Exit / Stay, same for triggers.
It is not so with compound colliders. Then you have multiple Colliders as children and only one rigidbody on the parent: this way the parent can detect collisions on the children if it has an OnCollisionEnter event handler. I realized that this cannot be done if the children, too, have rigidbodies. But really I have to attach a script to every one of the child game objects (like 30 of them) only to forward the collision event to the parent? :(