How can I stop a rigidbody (Ragdoll) character from colliding with the Character Controller capsule?


I’m using the Unity 5 Mechanim standard asset for the third person controller (“Ethan”). I want the character to be able to ragdoll, so instead of using a normal model I’m using the ragdoll model (so I can turn the character into a ragdoll just by switching off the animator component).

But (presumably) because of the rigidbodies, the mechanim doesn’t work while the player model is inside the capsule collider of the character controller. It jitters and keeps playing through all sort of animationsm or sometimes just crouches. When the ragdoll gets activated it goes flying off over the horizon.

Everything I’ve looked up to fix this says to put them on different layers to ignore each other. I’ve done this with the collision matrix as well as code, but it has no affect at all.

if I put the model outside of the char controller capsule it works perfectly (but then I get the offset controls of course).

I’m pretty sure this is a collision problem but I don’t know why they won’t ignore each other. Any help much appreciated, thanks for reading :slight_smile:

I got this crouch problem a few weeks ago and got it to work. The problem is the spherecasts in the standard ThidPersonCharacter. They are hitting the ragdoll colliders.

What I did was adding a public LayerMask to the script. Instead of using Physics.AllLayers in the two Physics.SphereCast on line 97 and 115 use this layermask. I set the mask to render all but the “Ignore Raycast” layer. In the inspector, select the Ethan Skeleton and change the layers to Ignore Raycast.

I’m a little late to the party, but maybe it can help someone :slight_smile:


Adding the code as requested.
Add a public Layer Mask.

public LayerMask raycastLayerMask;

Now on line 97-101 use the layer mask:

if (Physics.SphereCast(crouchRay, m_Capsule.radius * k_Half, crouchRayLength, raycastLayerMask.value, QueryTriggerInteraction.Ignore))
    m_Crouching = true;

On row 115-118 use the layer mask again:

if (Physics.SphereCast(crouchRay, m_Capsule.radius * k_Half, crouchRayLength, raycastLayerMask.value, QueryTriggerInteraction.Ignore))
    m_Crouching = true;

Remove Ignore Raycast(or use any other layer if you prefer).
Change the layer of the EthanSkeleton to Ignore Raycast. Press “Yes, change children”.