Short question - Do rigidbodies only use (compound) colliders in their immediate children or should they search down the entire heirachy for colliders?
More detailed info - I have a character model imported from somewhere (3dsmax I think) and I'm moving it around manually and playing animations when needed.
The model is set up like normal I think .
Base
-> Pelvis
-> Spine
-> L Thigh
-> R thigh
ect.
What I want to do is have this character knock things over in the scene when it moves around. So I attached a kinematic rigidbody to the base element, and I have a script on that that listens for collision events.
Then I add simple sphere or capsule colliders to a few of the joints. Like one on each leg, foot, arm, hand etc.
Now, it seems that a rigidbody will only use the colliders that are in it's immediate children, rather than searching down the heirachy to find all the colliders that exist.
Is that correct? When I put a big box collider on the Pelvis element (directly under the object with the rigidbody and script) it seems to work, but when the colliders only exist much further down the chain (feet etc) I get no collisions.
OnCollisionEnter() should be called on your parent GameObject that has the rigidbody regardless how deep the collider is in the hierarchy. At least that's how it works for me.
You said you have a kinematic rigidbody. Kinematic rigidbodies won't trigger OnCollisionEnter() unless they collide with a dynamic rigidbody. Maybe that's your problem?
I posted this on the other forum and mod andeeee posted this response which explains what I was seeing.
A rigidbody incorporates colliders on
all its descendants, not just
immediate children. However, colliders
on moving child objects will not
necessarily give the right effect
Child objects that are moved (say by
an animation) might be better handled
by having their own kinematic
rigidbody each. Each limb can have a
script that informs the root object of
collisions if necessary.
That makes sense now. Since my colliders were being moved by animations, the rigidbody at the root level was not picking up their collisions or triggers.
So, it looks like putting a Kinematic Rigidbody, Collider and simple script on each limb is the way to go.
Just tested that out and it works fine. The script on the limbs just uses SendMessageUpwards to send collision/trigger messages up to the root. Fairly simple.