- Home /
How do you set the positions of a ragdoll to that of bones in the last frame of played animation?
Hello, I have encountered a problem with my ragdolls in unity. The way I am doing ragdolls is prefabbing them and instantiated them when the main game object is killed.
They instantiate just fine but I am having trouble setting the positions of the bones to that of the animation at time of death.
Here is what I am doing:
GameObject ragdoll = Instantiate(m_ragdoll, transform.position, transform.rotation) as GameObject;
Utilities.ConfigureRagdollPosition(transform, ragdoll.transform);
ConfigureRagdollPosition():
public static void ConfigureRagdollPosition(Transform reference, Transform ragdollPart)
{
ragdollPart.localPosition = reference.localPosition;
ragdollPart.localRotation = reference.localRotation;
for (int i = 0; i < reference.childCount; i++)
{
Transform ref_t = reference.GetChild(i);
Transform rag_t = reference.GetChild(i);
if(ref_t != null && rag_t != null)
ConfigureRagdollPosition(ref_t, rag_t);
}
}
The ragdoll just starts up in the T pose, because I'm assuming that animations don't work the way I thought they did (i.e. moving the game objects with the bones).
What is the correct way of doing this?
Additional Info: I am currently working with the unity construction worker model and animations for this. Debug.Log shows that it is iterating through the children recursively.
Answer by GameVortex · Feb 04, 2014 at 12:56 PM
It seems to me that on line 8. and 9. of that script that you are setting the reference and the ragdoll to be the same transform and therefore will be setting the local position and rotation to be the same as it is. On line 9. you probably want to use the ragdollPart instead (assuming it has the same number of bones and the bones are named the same).
Other than that this is a great way of setting the position of bones for a ragdoll and animations do work by moving/translating the bones of gameObjects.
Oh my god! How the fudge did I miss that!! Super derp. It's always the simplest things. Sorry for wasting your time :D
Hi! I'm still having problems with this. Do you mean like this:
Transform ref_t = reference.GetChild(i);
Transform rag_t = ragdollPart.GetChild(i);
This didn't work in my case. :/
Is there anyway you could clarify the solution? I'm with Nadan, I tried that and it didn't seem to work. If you could post the fixed code you'd be my hero!
@Nadan & @Sussy Your issue might be different from what the Original Question is about. With just the information "It does not work" to go by it is not easy to fix the problem. You should post a new question about your specific issue and reference this question. Remember to provide as much details as possible.
Your answer
Follow this Question
Related Questions
Ignore Bones in Animation 1 Answer
Ragdoll only for specific limb 2 Answers
[C#] How would I create skeleton bone transforms from a TRS matrix? 0 Answers
Ragdoll on Only Part of a Model 2 Answers
save my ragdolls current pose in c# 1 Answer