Exemplo n.º 1
0
        static Collider AddBoxCollider(RagdollTransform bone, Bounds bounds)
        {
            BoxCollider box = bone.AddComponent <BoxCollider>();

            box.center = bounds.center;
            box.size   = bounds.size;
            return(box);
        }
Exemplo n.º 2
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.º 3
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;
            }
        }