/* * set the velocities we calculated in late update for each animated bone * on the actual ragdoll */ void SetPhysicsVelocities(float deltaTime) { float dot = Vector3.Dot(ragdoll.RootBone().transform.up, Vector3.up); float maxVelocityForGravityAdd2 = profile.maxGravityAddVelocity * profile.maxGravityAddVelocity; float fallDecayCurveSample = 1f - fallDecay; //set up curves backwards... whoops // for each physics bone... for (int i = 0; i < Ragdoll.bonesCount; i++) { HumanBodyBones unityBone = Ragdoll.humanBones[i]; RagdollTransform bone = ragdoll.GetBone(unityBone); if (ragdoll.BoneDismembered(bone)) { continue; } if (bone.rigidbody.isKinematic) { continue; } Vector3 ragdollBoneVelocty = bone.rigidbody.velocity; // get the manually set bone decay value float boneDecay = boneDecays[unityBone]; /* * calculate the force decay based on the overall fall decay and the bone profile's * fall force decay curve */ float forceDecay = Mathf.Clamp01(profile.boneData[unityBone].fallForceDecay.Evaluate(fallDecayCurveSample)); //subtract manual decay forceDecay = Mathf.Clamp01(forceDecay - boneDecay); // if we're flipped to extremely, stop trying to follow anim // makes it look like it's 'gliding' forward in superman stance if (dot < profile.loseFollowDot) { forceDecay = 0; } // if we're still using some force to follow if (forceDecay != 0) { Vector3 animVelocity = animationVelocityTrackers[i].velocity; /* * if animation velocity is below threshold magnitude, add some gravity to it */ if (animVelocity.sqrMagnitude < maxVelocityForGravityAdd2) { animVelocity.y = Physics.gravity.y * deltaTime; } /* * if bone decay was manually set to make room for external velocities, * use the most extreme component of each vector as the "target animated" velocity */ if (boneDecay != 0) { animVelocity = MaxAbs(ragdollBoneVelocty, animVelocity); } // set the velocity on the ragdoll rigidbody (based on the force decay) bone.rigidbody.velocity = Vector3.Lerp(ragdollBoneVelocty, animVelocity, forceDecay); } if (i != 0) { /* * calculate the force decay based on the overall fall decay and the bone profile's * fall force decay curve */ float torqueDecay = Mathf.Clamp01(profile.boneData[unityBone].fallTorqueDecay.Evaluate(fallDecayCurveSample)); //subtract manual decay torqueDecay = Mathf.Clamp01(torqueDecay - boneDecay); /* * handle joints target for the ragdoll joints */ HandleJointFollow(bone, profile.maxTorque * torqueDecay, i); } } CheckForFallEnd(fallDecay); }