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.