Exemplo n.º 1
0
        /*
         *
         *  actually add the rigidbody, collider, joint components that make up the ragdoll (if add components)
         *
         *  measure the initial head offset from chest
         */

        public static void BuildBones(Animator animator, RagdollProfile profile, bool addComponents, Dictionary <HumanBodyBones, RagdollTransform> boneElements, out float initialHeadOffsetFromChest)
        {
            if (addComponents)
            {
                EraseRagdoll(animator);

                //add capsules
                BuildCapsules(boneElements);
                AddBreastColliders(boneElements);
                AddHeadCollider(boneElements);

                //add rigidbodies
                BuildRigidodies(boneElements);

                //add joints
                BuildJoints(boneElements);

                //add bone components
                BuildBones(boneElements);
            }

            //initial head position from chest (used for resizing chest collider based on head offset)
            initialHeadOffsetFromChest = boneElements[HumanBodyBones.Chest].transform.InverseTransformPoint(boneElements[HumanBodyBones.Head].transform.position).y;

            // update the ragdoll to reflect it's profile values
            Ragdoll.UpdateBonesToProfileValues(boneElements, profile, initialHeadOffsetFromChest);
        }
 void CheckForProfileChange()
 {
     if (profile != ragdoll.ragdollProfile)
     {
         profile   = ragdoll.ragdollProfile;
         profileSO = profile != null ? new SerializedObject(profile) : null;
     }
 }
        /*
         *              Adjust Ragdoll component values per bone to reflect the supplied
         *              Ragdoll profile (default profile if none is supplied)
         */
        public static void UpdateBonesToProfileValues(Dictionary <HumanBodyBones, RagdollTransform> bones, RagdollProfile profile, float initialHeadOffsetFromChest)
        {
            if (bones == null)
            {
                return;
            }

            if (profile == null)
            {
                return;
            }

            Vector3 headOffset = profile.headOffset;

            //clamp head offset (values too high or too low become unstable for some reason)
            headOffset.y = Mathf.Clamp(headOffset.y, -initialHeadOffsetFromChest + .1f, 2);


            for (int i = 0; i < bonesCount; i++)
            {
                RagdollProfile.BoneProfile boneProfile = profile.boneData[humanBones[i]];

                HumanBodyBones hBodyBone = humanBones[i];

                RagdollTransform bone = bones[hBodyBone];


                //set rigidbody values for bone
                UpdateRigidbodyToProfile(bone.rigidbody, boneProfile);

                //adjust collider values for bone
                UpdateColliderToProfile(hBodyBone, bone.collider, boneProfile, headOffset, initialHeadOffsetFromChest);

                //set joint values
                if (bone.joint)
                {
                    UpdateJointToProfile(hBodyBone, bone.joint, boneProfile, headOffset);
                }
            }
        }