- Home /
Duplicate Question
Set the ragdoll position
Hi, I have a soldier's gameobject, and when his health goes to 0 I destroy this gameobject and I replace it with a soldier's ragdoll, the problem is that I want that the instantiated ragdoll has the same position and rotation (also for every child like arms,legs ecc..) of the precedent gameobject, but my script doesn't work because the ragdoll is istantieted in the t-pose... How could i adjust it?
var ragdoll: Transform = Instantiate(replacement, transform.position, transform.rotation);
var currentJoints= GetComponentsInChildren(Transform);
var ragdollJoints=ragdoll.GetComponentsInChildren(Transform)
for(var childRagdoll : Transform in ragdollJoints)
{
for(var childGameObject : Transform in currentJoints)
{
if(childGameObject.name.CompareTo(childRagdoll.name) == 0)
{
childRagdoll.position = childGameObject.position;
childRagdoll.rotation = childGameObject.rotation;
}
}
}
Destroy(this.gameObject);
Thanks in advice and sorry for my bad english!
So you want the "Ragdoll" to take the place of the soldier the second he dies and you want it to be in a position other than the T formation?...or do you want the body to fall on the ground realistically and all parts of it to have life like physics? just to clarify.
Yes, i want that the soldier be replaced by the ragdoll and i want that the initial pose of the ragdoll be the same of the soldier.. So in that way the death would be more realistic..
http://lmgtfy.com?q=Unity+ragdoll+position
Some people might not think lmgtfy links are appropriate, but when you can copy in the title of the question and get all the right answers I think the question deserves it.
Follow this Question
Related Questions
Find position of the GameObject this script is attached to. 2 Answers
Problem with transform 2 Answers
set position child of game object by name 2 Answers
How do I pick up a ragdoll 0 Answers