예제 #1
0
 void Update()
 {
     if (shakeMgr != null)
     {
         Vector3 vShake = shakeMgr.GetShakeDelta();
         transform.position += vShake;
     }
 }
예제 #2
0
    void LateUpdate()
    {
        if (m_trLook == null || m_curMatch == null || m_basket == null)
        {
            return;
        }

        if (m_Zoom == null || !m_Zoom.m_bZoomState)
        {
            float fTargetZPos = Mathf.Clamp(m_trLook.position.z, m_RadiusThresholdMinV, m_RadiusThresholdMaxV);

            float fRatioV = (fTargetZPos - m_RadiusThresholdMaxV) / (m_RadiusThresholdMinV - m_RadiusThresholdMaxV);
            fRatioV = Mathf.Clamp(fRatioV, 0.0f, 1.0f);

            float fLookAngleV    = Mathf.Lerp(m_MinLookAngleV, m_MaxLookAngleV, fRatioV);
            float fDistToTarget  = Mathf.Lerp(m_MinDistToTarget, m_MaxDistToTarget, fRatioV);
            float fAngleToTarget = Mathf.Lerp(m_MinAngleToTarget, m_MaxAngleToTarget, fRatioV);

            Vector3 dirLookV     = (Quaternion.AngleAxis(fLookAngleV, Vector3.right) * (Vector3.forward)).normalized;
            Vector3 dirToTargetV = (Quaternion.AngleAxis(fAngleToTarget, Vector3.right) * (Vector3.forward)).normalized;

            Vector3 cameraPosV = m_trLook.position - dirToTargetV * fDistToTarget;
            cameraPosV = new Vector3(0.0f, cameraPosV.y, cameraPosV.z);

            Vector3 vShootTargetPos = (Vector3)m_basket.m_vShootTarget;
            Vector3 dirLookH        = vShootTargetPos - transform.position;
            dirLookH.y = 0.0f;
            dirLookH.Normalize();

            float fAngleH = Vector3.Angle((Vector3.forward), dirLookH);
            if (Vector3.Cross((Vector3.forward), dirLookH).y < 0.0f)
            {
                fAngleH = -fAngleH;
            }

            transform.forward  = Quaternion.AngleAxis(fAngleH, Vector3.up) * dirLookV;
            transform.position = _UpdateViewBound(new Vector3(m_trLook.transform.position.x * m_MoveSpeedH, cameraPosV.y, cameraPosV.z));
        }
        else
        {
            m_Zoom.OnUpdate(Time.deltaTime);
        }

        Vector3 vShake = m_Shake.GetShakeDelta();

        transform.position += vShake;
    }
예제 #3
0
    public void Positioning(bool instantly = false)
    {
        if (m_trLook == null || m_curMatch == null)
        {
            return;
        }

        if (m_playGround == null)
        {
            m_playGround = m_curMatch.mCurScene.mGround;
        }
        if (m_focusBall == null)
        {
            m_focusBall = m_curMatch.mCurScene.mBall;
        }

        float fTargetZPos = Mathf.Clamp(m_trLook.position.z, m_RadiusThresholdMinV, m_RadiusThresholdMaxV);
        float fRatioV     = (fTargetZPos - m_RadiusThresholdMinV) / (m_RadiusThresholdMaxV - m_RadiusThresholdMinV);

        fRatioV = Mathf.Clamp(fRatioV, 0.0f, 1.0f);

        float fLookAngleV   = Mathf.Lerp(m_MinLookAngleV, m_MaxLookAngleV, fRatioV);
        float fHeightAdjust = 0.0f;

        if (m_focusBall != null && !m_Zoom.m_bZoomState)
        {
            if (m_focusBall.m_owner == null && m_focusBall.m_ballState != BallState.eUseBall_Pass)
            {
                float fDelta = m_focusBall.transform.position.y - m_MinBallEffectHeight;
                if (fDelta > 0.0f)
                {
                    fHeightAdjust = fDelta / (m_MaxBallEffectHeight - m_MinBallEffectHeight) * m_heightAdjust;
                }
            }
        }

        float fDistToTarget = Mathf.Lerp(m_MinDistToTarget, m_MaxDistToTarget, fRatioV);

        Vector3 dirLookV   = (Quaternion.AngleAxis(fLookAngleV, Vector3.right) * (Vector3.forward)).normalized;
        Vector3 cameraPosV = m_trLook.position - dirLookV * fDistToTarget;

        cameraPosV.y += m_CamHeightThreshold + fHeightAdjust;
        Vector3 logicCameraPos = _UpdateViewBound(new Vector3(m_trLook.transform.position.x, cameraPosV.y, cameraPosV.z));

        m_Staying = true;

        Vector3 speed = m_UseSwitchSpeed ? m_switchRoleSpeed : m_moveSpeed;

        if (m_Zoom == null || !m_Zoom.m_bZoomState)
        {
            float fAngleToTargetX   = Vector3.Angle(Vector3.forward, dirLookV);
            float fCurAngleX        = transform.localEulerAngles.x;
            float fTotalDeltaAngleX = fAngleToTargetX - fCurAngleX;
            if (!instantly)
            {
                fAngleToTargetX = Mathf.SmoothDampAngle(fCurAngleX, fAngleToTargetX, ref m_fCurRotateSpeedX, speed.x);
            }

            float fAngleToTargetY = 0f;
            float fCurAngleY      = transform.localEulerAngles.y;
            if (!instantly)
            {
                float maxAngleDeltaY = 1f;
                if (!Mathf.Approximately(fAngleToTargetX, fCurAngleX) && !Mathf.Approximately(fTotalDeltaAngleX, 0f))
                {
                    float angleDeltaRatio = (fAngleToTargetX - fCurAngleX) / fTotalDeltaAngleX;
                    maxAngleDeltaY = Mathf.Abs(fAngleToTargetY - fCurAngleY) * angleDeltaRatio;
                }
                fAngleToTargetY = Mathf.MoveTowardsAngle(fCurAngleY, fAngleToTargetY, maxAngleDeltaY);
                //fAngleToTargetY = Mathf.SmoothDampAngle(fCurAngleY, fAngleToTargetY, ref m_fCurRotateSpeedY, speed.z);
            }

            transform.rotation = Quaternion.Euler(fAngleToTargetX, fAngleToTargetY, 0.0f);

            if (!instantly)
            {
                if (GameUtils.HorizonalDistance(transform.position, logicCameraPos) > 0.01f)
                {
                    m_Staying = false;
                }

                if (m_UseSwitchSpeed)
                {
                    transform.position = new Vector3(
                        Mathf.SmoothDamp(transform.position.x, logicCameraPos.x, ref m_curSwitchSpeed.x, speed.x),
                        Mathf.SmoothDamp(transform.position.y, logicCameraPos.y, ref m_curSwitchSpeed.y, speed.y),
                        Mathf.SmoothDamp(transform.position.z, logicCameraPos.z, ref m_curSwitchSpeed.z, speed.z));
                }
                else
                {
                    transform.position = new Vector3(
                        Mathf.SmoothDamp(transform.position.x, logicCameraPos.x, ref m_curSpeed.x, speed.x),
                        Mathf.SmoothDamp(transform.position.y, logicCameraPos.y, ref m_curSpeed.y, speed.y),
                        Mathf.SmoothDamp(transform.position.z, logicCameraPos.z, ref m_curSpeed.z, speed.z));
                }
            }
            else
            {
                transform.position = logicCameraPos;
            }
        }
        else if (!instantly)
        {
            m_Zoom.OnUpdate(Time.deltaTime);
        }

        if (!instantly)
        {
            Vector3 vShake = m_Shake.GetShakeDelta();
            transform.position += vShake;
        }
    }