- Home /
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);
}
}
}
Answer by Eggtooth · Aug 16, 2017 at 12:26 PM
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.
http://perttuh.blogspot.fi/2013/10/unity-mecanim-and-ragdolls.html
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.
this script is attached to the ragdoll and player death script is calling copypose function
Well, I have made it that way and it works just fine here. However here I have full body awareness for both first person camera and third person one.
Your answer
Follow this Question
Related Questions
How to implement Mob movement / death ? 1 Answer
How to make is kinematic false for all children of a gameobject? 1 Answer
Animated pose, to ragdoll, to dead pose seamlessly 1 Answer
How to effect all objects in an array 2 Answers
How do I make enemies ragdoll after being shot with a Raycast in VR? 0 Answers