enabling ragdoll midair causes rigidbody to lose velocity (or reset)

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;
    }
}

@prismspecs

hi, that’s what I would try as first thing.

I’ve never used ragdolls, but you can try following:

  • Each frame (fixedUpdate) when falling store character velocity, if it’s a non-kinematic RigidBody:

rb.velocity (linear velocity)
rb.angularVelocity (same for rotation)

Then you can use stored force with rb.AddForce and specify ForceMode as velocity change.