void HandleBoneDecayOnCollision(float collisionMagnitude2, RagdollBone bone, bool isCrushed, Collision collision) { if (isCrushed) { //Debug.LogWarning(bone + " / " + collision.transform.name + " CrUSHED"); ragdollController.SetBoneDecay(bone.bone, 1, neighborDecayMultiplier); } // if the magnitude is above the minimum threshold for adding decay else if (collisionMagnitude2 >= decayMagnitudeRange.x * decayMagnitudeRange.x) { float magnitude = Mathf.Sqrt(collisionMagnitude2); //linearly interpolate decay between 0 and 1 base on collision magnitude float linearDecay = (magnitude - decayMagnitudeRange.x) / (decayMagnitudeRange.y - decayMagnitudeRange.x); //Debug.Log(bone + " / " + collision.transform.name + " mag: " + magnitude + " decay " + linearDecay); ragdollController.SetBoneDecay(bone.bone, linearDecay, neighborDecayMultiplier); } }
IEnumerator ShootBullet(Ray ray) { yield return(new WaitForFixedUpdate()); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, shootMask, QueryTriggerInteraction.Ignore)) { //check if we hit a ragdoll bone RagdollBone ragdollBone = hit.transform.GetComponent <RagdollBone>(); if (ragdollBone) { // check if the ragdoll has a controller if (ragdollBone.ragdoll.hasController) { RagdollController controller = ragdollBone.ragdoll.controller; // set bone decay for the hit bone, so the physics will affect it // slightly lower for neighbor bones float mainDecay = 1; float neighborMultiplier = .75f; controller.SetBoneDecay(ragdollBone.bone, mainDecay, neighborMultiplier); //make it go ragdoll controller.GoRagdoll(); } } // shoot normally Rigidbody rb = hit.transform.GetComponent <Rigidbody>(); if (rb) { rb.AddForceAtPosition(ray.direction.normalized * modifiedBulletForce, hit.point, ForceMode.VelocityChange); } } }