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);
        }
Exemplo n.º 2
0
 /*
  *  has to be public i guess...  :/
  */
 public void _InitializeInternal(HumanBodyBones bone, Ragdoll ragdoll, Action <RagdollBone, Collision> onCollisionEnter, Action <RagdollBone, Collision> onCollisionStay, Action <RagdollBone, Collision> onCollisionExit)
 {
     this.bone              = bone;
     this.ragdoll           = ragdoll;
     this.onCollisionEnter += onCollisionEnter;
     this.onCollisionStay  += onCollisionStay;
     this.onCollisionExit  += onCollisionExit;
 }
Exemplo n.º 3
0
        static void BuildCapsules(Dictionary <HumanBodyBones, RagdollTransform> bones)
        {
            foreach (var k in capsuleBones)
            {
                RagdollTransform bone = bones[k];

                int direction = k.ToString().Contains("Arm") ? 0 : 1;

                float distance;
                if (upperCapsuleBones.Contains(k))
                {
                    distance = bone.transform.InverseTransformPoint(bones[Ragdoll.GetChildBone(k)].transform.position)[direction];
                }
                else
                {
                    Vector3 endPoint = (bone.transform.position - bones[Ragdoll.GetParentBone(k)].transform.position) + bone.transform.position;
                    distance = bone.transform.InverseTransformPoint(endPoint)[direction];

                    if (bone.transform.GetComponentsInChildren(typeof(Transform)).Length > 1)
                    {
                        Bounds bounds = new Bounds();
                        foreach (Transform child in bone.transform.GetComponentsInChildren(typeof(Transform)))
                        {
                            bounds.Encapsulate(bone.transform.InverseTransformPoint(child.position));
                        }

                        if (distance > 0)
                        {
                            distance = bounds.max[direction];
                        }
                        else
                        {
                            distance = bounds.min[direction];
                        }
                    }
                }

                CapsuleCollider collider = bone.AddComponent <CapsuleCollider>();
                collider.direction = direction;

                Vector3 center = Vector3.zero;
                center[direction] = distance * 0.5F;
                collider.center   = center;

                collider.height = Mathf.Abs(distance);
                bone.collider   = collider;
            }
        }
Exemplo n.º 4
0
        static void BuildJoints(Dictionary <HumanBodyBones, RagdollTransform> bones)
        {
            foreach (var k in bones.Keys)
            {
                if (k == HumanBodyBones.Hips)
                {
                    continue;
                }

                RagdollTransform bone = bones[k];

                bone.joint = bone.AddComponent <ConfigurableJoint>();

                // Setup connection and axis

                //bone.joint.autoConfigureConnectedAnchor = false;

                // turn off to handle degenerated scenarios, like spawning inside geometry.
                bone.joint.enablePreprocessing = false;

                bone.joint.anchor        = Vector3.zero;
                bone.joint.connectedBody = bones[Ragdoll.GetParentBone(k)].rigidbody;

                // Setup limits
                SoftJointLimit limit = new SoftJointLimit();
                limit.contactDistance = 0; // default to zero, which automatically sets contact distance.
                limit.limit           = 0;

                bone.joint.lowAngularXLimit = bone.joint.highAngularXLimit = bone.joint.angularYLimit = bone.joint.angularZLimit = limit;

                bone.joint.xMotion        = bone.joint.yMotion = bone.joint.zMotion = ConfigurableJointMotion.Locked;
                bone.joint.angularXMotion = bone.joint.angularYMotion = bone.joint.angularZMotion = ConfigurableJointMotion.Limited;

                bone.joint.rotationDriveMode = RotationDriveMode.Slerp;

                bone.joint.projectionMode = JointProjectionMode.PositionAndRotation;
            }
        }
Exemplo n.º 5
0
 public DATATYPE this[HumanBodyBones bone] {
     get { return(boneDatas[Ragdoll.Bone2Index(bone)].boneData); }
 }
Exemplo n.º 6
0
 void OnEnable()
 {
     ragdoll = target as Ragdoll;
 }