I use internal Unity Ragdoll wizard. I create a prefab of ragdool, all working fine. I try to addForce to the ragdoll, but see error message:“MissingComponentException: There is no ‘Rigidbody’ attached to the “ragdollprefab(Clone)” game object, but a script is trying to access it.You probably need to add a Rigidbody to the game object “ragdollprefab(Clone)”. Or your script needs to check if the component is attached before using it.”
I use this script for a addForce.
var ragdollprefab:Transform;
var shootForce: float;
if(Input.GetKeyDown(KeyCode.Mouse0))
{
var instanceRagdoll = Instantiate(ragdollprefab, transform.position, Quaternion.identity);
instanceRagdoll.rigidbody.AddForce(transform.forward * shootForce);
}
The rigidbody is likely living on a nested part of your object hierarchy - just ran into this myself tonight, heres what should fix that:
Rigidbody rb = ragdoll.GetComponentInChildren( typeof( Rigidbody ) ) as Rigidbody;
Then call:
rb.AddForce( new Vector3( 0,0,100 ) );
Now my problem is that the addforce appears to do nothing for me! gah!
What most certainly happened here is that there were no proper connections between the armature joints and the necessary rigidbodies.
Simply put, there needs to be a parent-child relation between all the joints and their intended ‘pivot’ rigidbodies.
While this is normally solved by proper assignment of the body parts into the ragdoll wizard, there’s some models that you just can’t figure out.
Check out URG! to see how the body parts become related http://forum.unity3d.com/threads/107501-Release-URG!-The-ultimate-ragdoll-generator?p=713290