void InitializeVelocitySetValues()
        {
            animationVelocityTrackers = new VelocityTracker[Ragdoll.bonesCount];

            for (int i = 0; i < Ragdoll.bonesCount; i++)
            {
                RagdollTransform bone = ragdoll.GetBone(Ragdoll.humanBones[i]);

                //track position (offset by ragdoll bone's rigidbody centor of mass) of the follow target
                Vector3 massCenterOffset = bone.transform.InverseTransformPoint(bone.rigidbody.worldCenterOfMass);
                animationVelocityTrackers[i] = new VelocityTracker(bone.followTarget.transform, massCenterOffset);
            }
        }
        public void DismemberBone(Ragdoll ragdoll, RagdollTransform bone, int delay, bool isFollowBone = false)
        {
            InitializeDismemberedBones();

            if (!isFollowBone)
            {
                if (!dismemberableBones.Contains(bone.bone.bone))
                {
                    return;
                }

                if (delay > 0)
                {
                    ragdoll.StartCoroutine(DismemberBoneDelayed(ragdoll, bone, delay));
                    return;
                }

                dismemberedBones[bone.bone.bone] = bone;

                bone.collider.gameObject.layer = LayerMask.NameToLayer(ignorePhysicsLayer);

                // bone.joint.connectedBody = null;
                // bone.collider.isTrigger = true;
                // bone.SetKinematic(true);



                // dismember the follow target, so it reflects our dismemberment
                // (dismembers the animated model...)
                if (bone.followTarget != null)
                {
                    DismemberBone(ragdoll, bone.followTarget, 0, true);
                }

                // dismember and disable any child bones (helps physics from getting all jittery)
                HumanBodyBones childBone = Ragdoll.GetChildBone(bone.bone.bone);
                if (childBone != HumanBodyBones.Hips)
                {
                    RagdollTransform childBoneTransform = ragdoll.GetBone(childBone);
                    if (!BoneDismembered(childBoneTransform))
                    {
                        DismemberBone(ragdoll, childBoneTransform, 0, false);
                    }
                }
            }

            bone.transform.localScale = Vector3.one * dismemberScale;
        }
        void Start()
        {
            if (testRagdoll != null)
            {
                if (Ragdoll.BoneIsPhysicsBone(boneToHang))
                {
                    RigidbodyHangPoint hangPoint = gameObject.AddComponent <RigidbodyHangPoint>();

                    hangPoint.calculateOffset = calculateOffset;
                    hangPoint.freeRotation    = freeRotation;
                    hangPoint.anchorOffset    = anchorOffset;
                    hangPoint.rigidbodyToHang = testRagdoll.GetBone(boneToHang).rigidbody;
                }

                else
                {
                    Debug.LogError(boneToHang + " Is not a ragdoll physics bone");
                }
            }
        }
示例#4
0
        public void DismemberBone(string reason, Ragdoll ragdoll, RagdollTransform bone)
        {
            InitializeDismemberedBones();
            if (!dismembermentAvailable)
            {
                return;
            }
            if (!BoneDismemberable(bone.bone.bone))
            {
                return;
            }
            if (RagdollPhysics.RigidbodyGrabbed(bone.rigidbody))
            {
                return;
            }

            // Debug.LogError("Dismembered " + reason);

            dismemberedBones[bone.bone.bone] = bone;

            // dismember the follow target, so it reflects our dismemberment
            // (dismembers the animated model...)
            if (bone.followTarget != null)
            {
                DismemberBone(ragdoll, bone.followTarget, true);
            }

            // dismember and disable any child bones (helps physics from getting all jittery)
            HumanBodyBones   childBone          = Ragdoll.GetChildBone(bone.bone.bone);
            RagdollTransform childBoneTransform = ragdoll.GetBone(childBone);

            if (!BoneDismembered(childBoneTransform))
            {
                DismemberBone(reason, ragdoll, childBoneTransform);
            }


            ragdoll.StartCoroutine(DismemberBoneDelayed(ragdoll, bone));
        }