Right now I have some code that, on click, turns my mecanim into a ragdoll. It works well other than the fact that when I do that, the velocity of all my little business man’s bodyparts resets to zero. Or that’s my best guess as to what is going on.
In theory, I’m thinking I could apply the downward velocity of my overall rigidbody before the ragdoll is enabled to all the joints of the ragdoll, but I’m not sure. Any advice appreciated!
public class walk : MonoBehaviour {
public Rigidbody rb;
public Component[] bones;
private bool isRagdoll = false;
// Use this for initialization
void Start () {
bones = gameObject.GetComponentsInChildren<Rigidbody> ();
rb = GetComponent<Rigidbody>();
DisableRagdoll ();
}
// Update is called once per frame
void Update () {
if(!isRagdoll)
transform.Translate (Vector3.forward * Time.deltaTime);
if (Input.anyKeyDown) {
GetComponent<Animator> ().enabled = false;
EnableRagdoll ();
}
}
void EnableRagdoll() {
isRagdoll = true;
// rb.isKinematic = false;
// rb.detectCollisions = true;
foreach (Rigidbody ragdoll in bones) {
ragdoll.isKinematic = false;
ragdoll.detectCollisions = true;
}
}
void DisableRagdoll() {
//rb.isKinematic = true;
//rb.detectCollisions = false;
foreach (Rigidbody ragdoll in bones) {
ragdoll.isKinematic = true;
//ragdoll.detectCollisions = false;
}
rb.isKinematic = false;
}
}