Ejemplo n.º 1
0
        private static bool FlipAxis(Joint joint, Axis axis)
        {
            Vector3 direction = Vector3.Normalize(joint.transform.position - joint.connectedBody.worldCenterOfMass);

            CapsuleCollider capsuleCollider = joint.GetComponent<CapsuleCollider>();
            if (capsuleCollider != null) {
                direction = Vector3.Normalize(joint.transform.position - (joint.transform.position - (joint.transform.rotation * capsuleCollider.center)));
            }

            switch(axis) {
            case Axis.X:
                return Vector3.Dot(joint.transform.right, direction) < 0;
            case Axis.Y:
                return Vector3.Dot(joint.transform.up, direction) < 0;
            default: return Vector3.Dot(joint.transform.forward, direction) < 0;
            }
        }
Ejemplo n.º 2
0
        private static Axis GetViewAxis(Joint joint)
        {
            if (joint.connectedBody == null) return Axis.Z;

            CapsuleCollider capsule = joint.GetComponent<CapsuleCollider>();
            if (capsule != null && capsule.center != Vector3.zero) return AxisTools.ToAxis(capsule.center);
            else {
                BoxCollider box = joint.GetComponent<BoxCollider>();
                if (box != null && box.center != Vector3.zero) return AxisTools.ToAxis(box.center);
            }

            return AxisTools.GetAxisToPoint(joint.transform, joint.connectedBody.worldCenterOfMass);
        }