- Home /
The question is answered, right answer was accepted
Make Body go limp after dead
Ok, so I'm workin and an fps survival type game. I have a healthh script and when my health < 0 it call a "Dead" function and will destroy game object.
How would I script it to go limp (Like ragdoll?) fall to the ground according to physics and the destroy object(on a timer?)
I kind of have an idea but I'm still learning Javascript in Unity.
function Dead()
{
Debug.Log("Im Dead");
//destroy enemy
Destroy(gameObject);
}
Answer by ExTheSea · May 06, 2013 at 07:00 PM
So for the ragdoll: You have to create a ragdoll replacement for your Gameobject. To do that you can use the ragdoll wizard ( http://docs.unity3d.com/Documentation/Components/wizard-RagdollWizard.html ).
To destroy the replacement you attach a script to the ragdoll containing something like this:
var destroyTime : float = 10.0f;
function Start(){
Destroy(gameObject, destroyTime); //Not quite sure if it really uses a float or an int.
}
Then if you call Dead you destroy your current "alive" Gameobject ( or move it somewhere or deactivate it whatever suits your purpose ) and Instantiate the Ragdoll at the position and with the rotation of the "alive" GameObject.
Hope it helps.
Thanks for the quick answer!!
I knew it would be simple
How would I Instantiate the ragdoll at the exact position and everything?? You know so it would look seamless?
I haven't tried this yet but I've been thinking about how it's do that
You could do something like this:
function Dead(){
Instantiate(Ragdoll, transform.position, transform.rotation); //First use the player to get the position and rotation
Destroy(gameobject); //Then destroy the player
}
I myself use similar code for my ragdoll-spawning.