- Home /
Collision with rigidbody inside a gameobject
So, I have a ragdoll model with Rigidbody and collider on each bone. All bones are in Armature object, and the armature along with the mesh are in main object (Unity does this by default when importing models).
Now, when I spawn the ragdoll and shoot it, it stops on the wall (that only has mesh collider), but it doesn't seem to register any collisions beyond that. I tried detecting collisions with script attached to the main gameObject via simple onCollisionEnter() function, but it doesn't even print anything out. I thought it's because it's the gameObject that's colliding and it doesn't have any rigidbody or mesh collider (it cannot have, when I add it, the ragdoll stops working for some reason, perhaps it's nesting somehow). I didn't want to attach the detection script to each bone, so I decided to attach the detection script to the player character:
void onCollisionEnter(Collision col){
print (col.gameObject.name);
rogi = col.gameObject.GetComponentsInChildren<Rigidbody> ();
for (int i = 0; i< rogi.GetLength(0); i++) {
rogi[i].useGravity = true;
}
}
while rogi is a Rigidbody Array, obviously. This, however, doesn't work also. There's no print, and the ragdoll doesn't react anyhow (it's gravity is off by default so it should change on collision). I believe that I should fix the GetComponentsInChildren to getting all the children from the main gameobject since the col would be a children bone, but still - at least there should be a print in console, and there is none. The player character that bears this script has both rigidbody and box collider.
What am I doing wrong here? Do I have to attach the colliders somehow else?
Thanks.