예제 #1
0
        public override void DoUpdate()
        {
            base.DoUpdate();

            if (!m_target)
            {
                return; //do nothing if no target is specified
            }
            Quaternion initQ = m_tr.rotation;
            Quaternion endQ  = Quaternion.identity;

            Vector3 selfPos   = m_tr.position;
            Vector3 targetPos = m_target.position;
            Vector3 dir       = (targetPos - selfPos).normalized;

            if (dir == Vector3.zero)
            {
                dir = m_prevDir;
            }

            m_prevDir = dir;

            endQ = QUtil.LookAt(m_lookAxis, m_upAxis, dir);

            if (!Mathf.Approximately(m_influence, 1f))
            {
                endQ = Quaternion.Slerp(initQ, endQ, m_influence);
            }

            m_tr.rotation = endQ;
        }
예제 #2
0
        public override void DoUpdate()
        {
            base.DoUpdate();

            if (!m_targetSpline)
            {
                return;                                          //do nothing if no target is specified
            }
            Vector3    initPos = m_tr.GetPosition(ESpace.World); //use world space
            Quaternion initRot = m_tr.GetQuaternion(ESpace.World);
            Vector3    endPos  = initPos;
            Quaternion endRot  = m_tr.rotation;
            Vector3    endTan  = Vector3.forward;
            Vector3    endUp   = Vector3.up;



            if (m_followCurve)
            { // calculate pos/tan/up together
                m_targetSpline.CalcTransformed(m_offset, out endPos, out endTan, out endUp);
                endRot = QUtil.LookAt(m_forwardDir, m_upDir, endTan, endUp);
            }
            else
            { // calculate pos only
                endPos = m_targetSpline.GetTransformedPosition(m_offset);
            }

            if (!Mathf.Approximately(m_influence, 1f))
            {
                endPos = Misc.Lerp(initPos, endPos, m_influence);
                if (m_followCurve)
                {
                    endRot = Quaternion.Slerp(initRot, endRot, m_influence);
                }
            }

            m_tr.SetPosition(endPos, ESpace.World);
            m_tr.SetQuaternion(endRot, ESpace.World);
        }
예제 #3
0
        public override void DoUpdate()
        {
            base.DoUpdate();

            if (!m_target)
            {
                return; //do nothing if no target is specified
            }
            Quaternion initRot   = m_tr.rotation;
            Vector3    selfPos   = m_tr.position;
            Vector3    targetPos = m_target.position;

            Vector3 upDir = Vector3.up;

            switch (m_RotateAxis)
            {
            case EAxisD.X: upDir = m_tr.right; break;

            case EAxisD.Y: upDir = m_tr.up; break;

            case EAxisD.Z: upDir = m_tr.forward; break;

            default: Dbg.LogErr("LockedTrack.DoUpdate: unexpected rotate axis: {0}", m_RotateAxis); break;
            }

            Vector3 lookDir     = targetPos - selfPos;
            Vector3 projLookDir = Vector3.ProjectOnPlane(lookDir, upDir);

            if (projLookDir != Vector3.zero)
            {
                Quaternion endRot = QUtil.LookAt(m_LookAxis, m_RotateAxis, projLookDir, upDir);
                if (!Mathf.Approximately(m_influence, 1f))
                {
                    endRot = Quaternion.Slerp(initRot, endRot, m_influence);
                }
                m_tr.SetQuaternion(endRot, ESpace.World);
            }
        }