Ragdoll Death Script

can any1 plz tell me how to make a ragdoll death script ie If a player dies then i want the player to be destroyed and ragdoll to come, taking the position of the player…right now the instantiated ragdoll is taking the position and rotation of the player but not the positions and rotation of the bones… this is my script for bones positioning which is not working…

public class Ragdoll : MonoBehaviour
{

private List<Transform> poseBones = new List<Transform>();
private List<Transform> ragdollBones = new List<Transform>();

public void CopyPose(Transform pose)
{
	AddChildren(pose, poseBones);
	AddChildren(transform, ragdollBones);

	foreach (Transform b in poseBones)
	{
		
		foreach (Transform r in ragdollBones)
		{
		
			if (r.name == b.name)
			{
				r.eulerAngles = b.eulerAngles;
		
				break;
			}
		}
	}
}

public void AddChildren(Transform parent, List<Transform> list)
{
	list.Add(parent);
	foreach (Transform t in parent)
	{					
		AddChildren(t, list);
	}
}

}

Actually I have created that very thing lately. You do NOT need to replace anything with ragdoll. I’ve used one model that ragdolled upon death.

The Gist of it is basically being able to smoothly transform from mecanim to ragoll. Download Ragdoll Helper for that.

First, make sure that all ragdoll colliders are set to kinematic. Ragdoll Helper does that for you automatically, in my project I use PuppetMaster for Ragdoll and I think Ragdoll Helper finds by itself Rigidbodies and sets them to kinematic, and basically upon death all you need to do is call boolean

ragdoll.ragdolled = true

…to successfully ragdoll character and set all rigidbodies to Non-Kinematic. YOU MUST REMEMBER: Have character as humanoid and have bones correctly attached.

Next, after this, you will need to make separate layers for ragdoll colliders and collider for the character controller itself. Basically make so ragdoll collider doesn’t collide with the collider that is used for third/first person (preventing physics from freaking out) in physics settings. Then, upon death, make sure all ragdoll Rigidbodies are NOT set to Kinematic (which will be taken care by Ragdoll Helper itself), turn on Kinematic for player controller and turn off character controller collider as well.

Excuse me if explanation is convoluted, but I’ve explained best I could.

Keep in mind that the solution I have shown is good only for third person/2,5D/TopDown games/FPS with full body awareness.