Beispiel #1
0
 Vector3 contactDirection(TelescopeShell shell, bool reversed)
 {
     if (!reversed)
     {
         return(shell.transform.forward);
     }
     else
     {
         Vector3 dirLocal = shell.getLocalRotationAlongPath(1) * Vector3.forward;
         Vector3 dir      = shell.transform.rotation * dirLocal;
         dir *= -1;
         return(dir);
     }
 }
Beispiel #2
0
        public void SetTransform()
        {
            float extendT = Mathf.Clamp01(extensionRatio * 2);

            if (AlwaysExtend)
            {
                extendT = 1;
            }
            float twistT = Mathf.Clamp01(extensionRatio * 2 - 1);

            if (!Reversed)
            {
                Vector3    localTranslation = getLocalLocationAlongPath(extendT);
                Quaternion localRotation    = getLocalRotationAlongPath(extendT);

                // Add twist angle.
                Vector3    forwardAxis = localRotation * baseRotation * Vector3.forward;
                Quaternion roll        = Quaternion.AngleAxis(-twistAngle * twistT, forwardAxis);
                localRotation = roll * localRotation;

                // Set the shell's local translation from parent based on how extended it is.
                transform.localPosition = baseRotation * localTranslation + baseTranslation;
                transform.localRotation = baseRotation * localRotation;
            }

            else
            {
                TelescopeShell parent = transform.parent.GetComponent <TelescopeShell>();
                if (!parent)
                {
                    return;
                }

                Vector3    localTranslation = parent.getInvLocationAlongPath(extendT);
                Quaternion localRotation    = parent.getLocalRotationAlongPath(extendT);

                Vector3    forwardPosition = Quaternion.Inverse(baseRotation) * localTranslation - parent.baseTranslation;
                Quaternion forwardRotation = Quaternion.Inverse(parent.baseRotation) * Quaternion.Inverse(localRotation);

                // Set the shell's local translation from parent based on how extended it is.
                transform.localRotation = forwardRotation;
                transform.localPosition = forwardPosition;

                // Now we need to rotate by the twist angle, with the pivot being the parent's angle.
                Vector3 parentWorld = parent.transform.position;
                Vector3 axis        = parent.transform.forward;
                transform.RotateAround(parentWorld, axis, parent.twistAngle * twistT);
            }
        }
Beispiel #3
0
        public Vector3 LocalContactTangent()
        {
            TelescopeShell firstShell = shells[0];

            if (!Reversed)
            {
                Quaternion local = firstShell.transform.localRotation;
                return(local * Vector3.forward);
            }
            else
            {
                Quaternion baseQ = firstShell.transform.localRotation;
                Quaternion pathQ = firstShell.getLocalRotationAlongPath(1);

                Quaternion local = baseQ * pathQ;

                return(-(local * Vector3.forward));
            }
        }
Beispiel #4
0
        /*
         * public Vector3 WorldEndPosition()
         * {
         *  TelescopingShell lastShell = shells[shells.Count - 1];
         * }*/

        public Vector3 WorldEndTangent()
        {
            TelescopeShell lastShell = shells[shells.Count - 1];

            if (!Reversed)
            {
                Quaternion baseQ    = lastShell.transform.rotation;
                Quaternion local    = lastShell.getLocalRotationAlongPath(1);
                Quaternion combined = baseQ * local;

                Vector3 worldForward = combined * Vector3.forward;
                return(-worldForward);
            }

            else
            {
                Quaternion local = lastShell.transform.rotation;
                return(local * Vector3.forward);
            }
        }