Пример #1
0
        public override void Execute(float deltaTime)
        {
            float        t       = NormalizedT;
            BezierSpline spline  = Spline;
            bool         forward = MovingForward;

            for (int i = 0; i < tailObjects.Count; i++)
            {
                Transform tailObject = tailObjects[i];

                if (forward)
                {
                    if (!tailObject)
                    {
                        return;
                    }
                    tailObject.position = Vector3.Lerp(tailObject.position, spline.MoveAlongSpline(ref t, -tailObjectDistances[i]), movementLerpModifier * deltaTime);

                    if (lookAt == LookAtMode.Forward)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, Quaternion.LookRotation(spline.GetTangent(t)), rotationLerpModifier * deltaTime);
                    }
                    else if (lookAt == LookAtMode.SplineExtraData)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, spline.GetExtraData(t, InterpolateExtraDataAsQuaternion), rotationLerpModifier * deltaTime);
                    }
                }
                else
                {
                    tailObject.position = Vector3.Lerp(tailObject.position, spline.MoveAlongSpline(ref t, tailObjectDistances[i]), movementLerpModifier * deltaTime);

                    if (lookAt == LookAtMode.Forward)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, Quaternion.LookRotation(-spline.GetTangent(t)), rotationLerpModifier * deltaTime);
                    }
                    else if (lookAt == LookAtMode.SplineExtraData)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, spline.GetExtraData(t, InterpolateExtraDataAsQuaternion), rotationLerpModifier * deltaTime);
                    }
                }
            }
        }
        public override void Execute(float deltaTime)
        {
            float        t       = NormalizedT;
            BezierSpline spline  = Spline;
            bool         forward = MovingForward;

            for (int i = 0; i < tailObjects.Count; i++)
            {
                Transform tailObject = tailObjects[i];

                if (forward)
                {
                    tailObject.position = Vector3.Lerp(tailObject.position, spline.MoveAlongSpline(ref t, -tailObjectDistances[i]), movementLerpModifier * deltaTime);

                    if (lookAt == LookAtMode.Forward)
                    {
                        BezierSpline.PointIndexTuple tuple = spline.GetNearestPointIndicesTo(t);
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, Quaternion.LookRotation(tuple.GetTangent(), tuple.GetNormal()), rotationLerpModifier * deltaTime);
                    }
                    else if (lookAt == LookAtMode.SplineExtraData)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, spline.GetExtraData(t, extraDataLerpAsQuaternionFunction), rotationLerpModifier * deltaTime);
                    }
                }
                else
                {
                    tailObject.position = Vector3.Lerp(tailObject.position, spline.MoveAlongSpline(ref t, tailObjectDistances[i]), movementLerpModifier * deltaTime);

                    if (lookAt == LookAtMode.Forward)
                    {
                        BezierSpline.PointIndexTuple tuple = spline.GetNearestPointIndicesTo(t);
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, Quaternion.LookRotation(-tuple.GetTangent(), tuple.GetNormal()), rotationLerpModifier * deltaTime);
                    }
                    else if (lookAt == LookAtMode.SplineExtraData)
                    {
                        tailObject.rotation = Quaternion.Lerp(tailObject.rotation, spline.GetExtraData(t, extraDataLerpAsQuaternionFunction), rotationLerpModifier * deltaTime);
                    }
                }
            }
        }
Пример #3
0
        public override void Execute(float deltaTime)
        {
            BezierSpline spline  = Spline;
            float        t       = highQuality ? spline.evenlySpacedPoints.GetPercentageAtNormalizedT(NormalizedT) : NormalizedT;
            bool         forward = MovingForward;

            for (int i = 0; i < tailObjects.Count; i++)
            {
                Transform tailObject = tailObjects[i];
                Vector3   tailPosition;
                float     tailNormalizedT;
                if (highQuality)
                {
                    if (forward)
                    {
                        t -= tailObjectDistances[i] / spline.evenlySpacedPoints.splineLength;
                    }
                    else
                    {
                        t += tailObjectDistances[i] / spline.evenlySpacedPoints.splineLength;
                    }

                    tailNormalizedT = spline.evenlySpacedPoints.GetNormalizedTAtPercentage(t);
                    tailPosition    = spline.GetPoint(tailNormalizedT);
                }
                else
                {
                    tailPosition    = spline.MoveAlongSpline(ref t, forward ? -tailObjectDistances[i] : tailObjectDistances[i]);
                    tailNormalizedT = t;
                }

                tailObject.position = Vector3.Lerp(tailObject.position, tailPosition, movementLerpModifier * deltaTime);

                if (lookAt == LookAtMode.Forward)
                {
                    BezierSpline.Segment segment = spline.GetSegmentAt(tailNormalizedT);
                    tailObject.rotation = Quaternion.Lerp(tailObject.rotation, Quaternion.LookRotation(forward ? segment.GetTangent() : -segment.GetTangent(), segment.GetNormal()), rotationLerpModifier * deltaTime);
                }
                else if (lookAt == LookAtMode.SplineExtraData)
                {
                    tailObject.rotation = Quaternion.Lerp(tailObject.rotation, spline.GetExtraData(tailNormalizedT, extraDataLerpAsQuaternionFunction), rotationLerpModifier * deltaTime);
                }
            }
        }
Пример #4
0
        public override void Execute(float deltaTime)
        {
            float targetSpeed = (isGoingForward) ? speed : -speed;

            Vector3 targetPos = spline.MoveAlongSpline(ref m_normalizedT, targetSpeed * deltaTime);

            transform.position = targetPos;
            //transform.position = Vector3.Lerp( transform.position, targetPos, movementLerpModifier * deltaTime );

            bool movingForward = MovingForward;

            if (lookAt == LookAtMode.Forward)
            {
                Quaternion targetRotation;
                if (movingForward)
                {
                    targetRotation = Quaternion.LookRotation(spline.GetTangent(m_normalizedT));
                }
                else
                {
                    targetRotation = Quaternion.LookRotation(-spline.GetTangent(m_normalizedT));
                }

                transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationLerpModifier * deltaTime);
            }
            else if (lookAt == LookAtMode.SplineExtraData)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, spline.GetExtraData(m_normalizedT, extraDataLerpAsQuaternionFunction), rotationLerpModifier * deltaTime);
            }

            if (movingForward)
            {
                if (m_normalizedT >= 1f)
                {
                    if (travelMode == TravelMode.Once)
                    {
                        m_normalizedT = 1f;
                    }
                    else if (travelMode == TravelMode.Loop)
                    {
                        m_normalizedT -= 1f;
                    }
                    else
                    {
                        m_normalizedT  = 2f - m_normalizedT;
                        isGoingForward = !isGoingForward;
                    }

                    if (!onPathCompletedCalledAt1)
                    {
                        onPathCompletedCalledAt1 = true;
#if UNITY_EDITOR
                        if (UnityEditor.EditorApplication.isPlaying)
#endif
                        onPathCompleted.Invoke();
                    }
                }
                else
                {
                    onPathCompletedCalledAt1 = false;
                }
            }
            else
            {
                if (m_normalizedT <= 0f)
                {
                    if (travelMode == TravelMode.Once)
                    {
                        m_normalizedT = 0f;
                    }
                    else if (travelMode == TravelMode.Loop)
                    {
                        m_normalizedT += 1f;
                    }
                    else
                    {
                        m_normalizedT  = -m_normalizedT;
                        isGoingForward = !isGoingForward;
                    }

                    if (!onPathCompletedCalledAt0)
                    {
                        onPathCompletedCalledAt0 = true;
#if UNITY_EDITOR
                        if (UnityEditor.EditorApplication.isPlaying)
#endif
                        onPathCompleted.Invoke();
                    }
                }
                else
                {
                    onPathCompletedCalledAt0 = false;
                }
            }
        }
Пример #5
0
        public override void Execute(float deltaTime)
        {
            if (curSpline != null)
            {
                transform.position = Vector3.Lerp(transform.position, curSpline.GetPoint(m_normalizedT), movementLerpModifier * deltaTime);

                if (lookAt == LookAtMode.Forward)
                {
                    Quaternion targetRotation;
                    if (isGoingForward)
                    {
                        targetRotation = Quaternion.LookRotation(curSpline.GetTangent(m_normalizedT));
                    }
                    else
                    {
                        targetRotation = Quaternion.LookRotation(-curSpline.GetTangent(m_normalizedT));
                    }

                    transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationLerpModifier * deltaTime);
                }
                else if (lookAt == LookAtMode.SplineExtraData)
                {
                    transform.rotation = Quaternion.Lerp(transform.rotation, curSpline.GetExtraData(m_normalizedT, InterpolateExtraDataAsQuaternion), rotationLerpModifier * deltaTime);
                }

                if (isGoingForward)
                {
                    m_normalizedT += deltaTime / n_travelTime;

                    if (m_normalizedT > 1f)
                    {
                        if (!onPathCompletedCalledAt1)
                        {
                            onPathCompletedCalledAt1 = true;
#if UNITY_EDITOR
                            if (UnityEditor.EditorApplication.isPlaying)
#endif
                            onPathCompleted.Invoke();
                        }

                        if (travelMode == TravelMode.Once)
                        {
                            m_normalizedT = 1f;
                        }
                        else if (travelMode == TravelMode.Loop)
                        {
                            m_normalizedT -= 1f;
                        }
                        else
                        {
                            m_normalizedT  = 2f - m_normalizedT;
                            isGoingForward = false;
                        }
                    }
                    else
                    {
                        onPathCompletedCalledAt1 = false;
                    }
                }
                else
                {
                    m_normalizedT -= deltaTime / n_travelTime;

                    if (m_normalizedT < 0f)
                    {
                        if (!onPathCompletedCalledAt0)
                        {
                            onPathCompletedCalledAt0 = true;
#if UNITY_EDITOR
                            if (UnityEditor.EditorApplication.isPlaying)
#endif
                            onPathCompleted.Invoke();
                        }

                        if (travelMode == TravelMode.Once)
                        {
                            m_normalizedT = 0f;
                        }
                        else if (travelMode == TravelMode.Loop)
                        {
                            m_normalizedT += 1f;
                        }
                        else
                        {
                            m_normalizedT  = -m_normalizedT;
                            isGoingForward = true;
                        }
                    }
                    else
                    {
                        onPathCompletedCalledAt0 = false;
                    }
                }
            }
        }
        public override void Execute(float deltaTime)
        {
            float _normalizedT = highQuality ? spline.evenlySpacedPoints.GetNormalizedTAtPercentage(m_normalizedT) : m_normalizedT;

            transform.position = Vector3.Lerp(transform.position, spline.GetPoint(_normalizedT), movementLerpModifier * deltaTime);

            if (lookAt == LookAtMode.Forward)
            {
                BezierSpline.Segment segment = spline.GetSegmentAt(_normalizedT);
                Quaternion           targetRotation;
                if (isGoingForward)
                {
                    targetRotation = Quaternion.LookRotation(segment.GetTangent(), segment.GetNormal());
                }
                else
                {
                    targetRotation = Quaternion.LookRotation(-segment.GetTangent(), segment.GetNormal());
                }

                transform.rotation = Quaternion.Lerp(transform.rotation, targetRotation, rotationLerpModifier * deltaTime);
            }
            else if (lookAt == LookAtMode.SplineExtraData)
            {
                transform.rotation = Quaternion.Lerp(transform.rotation, spline.GetExtraData(_normalizedT, extraDataLerpAsQuaternionFunction), rotationLerpModifier * deltaTime);
            }

            if (isGoingForward)
            {
                m_normalizedT += deltaTime / travelTime;

                if (m_normalizedT > 1f)
                {
                    if (travelMode == TravelMode.Once)
                    {
                        m_normalizedT = 1f;
                    }
                    else if (travelMode == TravelMode.Loop)
                    {
                        m_normalizedT -= 1f;
                    }
                    else
                    {
                        m_normalizedT  = 2f - m_normalizedT;
                        isGoingForward = false;
                    }

                    if (!onPathCompletedCalledAt1)
                    {
                        onPathCompletedCalledAt1 = true;
#if UNITY_EDITOR
                        if (UnityEditor.EditorApplication.isPlaying)
#endif
                        onPathCompleted.Invoke();
                    }
                }
                else
                {
                    onPathCompletedCalledAt1 = false;
                }
            }
            else
            {
                m_normalizedT -= deltaTime / travelTime;

                if (m_normalizedT < 0f)
                {
                    if (travelMode == TravelMode.Once)
                    {
                        m_normalizedT = 0f;
                    }
                    else if (travelMode == TravelMode.Loop)
                    {
                        m_normalizedT += 1f;
                    }
                    else
                    {
                        m_normalizedT  = -m_normalizedT;
                        isGoingForward = true;
                    }

                    if (!onPathCompletedCalledAt0)
                    {
                        onPathCompletedCalledAt0 = true;
#if UNITY_EDITOR
                        if (UnityEditor.EditorApplication.isPlaying)
#endif
                        onPathCompleted.Invoke();
                    }
                }
                else
                {
                    onPathCompletedCalledAt0 = false;
                }
            }
        }