コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        ThirdPersonWallCover.CoverInfo coverInfo = playerInstance.GetCoverInfo();
        if (coverInfo.inCover == -1)
        {
            // When not inCover, the camMode is always eCamMode.far
            camMode = eCamMode.far;
        }
        else
        {
            // When inCover, the camMode switches to eCamMode.near_ if the player
            //  is near the edge of cover
            if (coverInfo.zoomL && !coverInfo.zoomR)
            {
                camMode = eCamMode.nearR;
            }
            else if (!coverInfo.zoomL && coverInfo.zoomR)
            {
                camMode = eCamMode.nearL;
            }
            else
            {
                camMode = eCamMode.far;
            }
        }

        // This is initially [0,0,0] to show the issue visually by jumping the Camera
        // to the origin if the position is not set properly in the switch statement.
        Vector3    pDesired   = Vector3.zero;
        Quaternion rotDesired = Quaternion.identity;

        switch (camMode)
        {
        case eCamMode.far:
            pDesired   = playerInstance.transform.position + relativePosFar;
            rotDesired = Quaternion.Euler(xRotationFar, 0, 0);
            break;

        case eCamMode.nearL:
        case eCamMode.nearR:
            // Desired position should be relative to playerInstance facing and position
            Vector3 pRelative = relativePosNear;
            pRelative.x += (camMode == eCamMode.nearL) ? -relativePosNearLRShift
                    : relativePosNearLRShift;
            pDesired   = playerInstance.transform.TransformPoint(pRelative);
            rotDesired = Quaternion.Euler(xRotationNear, coverInfo.inCover * 90, 0);
            break;
        }

        Vector3 pInterp = (1 - cameraEasing) * transform.position + cameraEasing * pDesired;

        transform.position = pInterp;

        Quaternion rotInterp = Quaternion.Slerp(transform.rotation, rotDesired, cameraEasing);

        transform.rotation = rotInterp;
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        ThirdPersonWallCover.CoverInfo coverInfo = playerInstance.GetCoverInfo();
        if (coverInfo.inCover == -1)
        {
            // When not inCover, the camMode is always eCamMode.far
            camMode = eCamMode.far;
        }
        else
        {
            // When inCover, the camMode switches to eCamMode.near_ if the player is near the edge of cover

            // But for now, until that challenge, it's always eCamMode.far.
            camMode = eCamMode.far;
        }

        // This is initially [0,0,0] to show the issue visually by jumping the Camera
        // to the origin if the position is not set properly in the switch statement.
        Vector3    pDesired   = Vector3.zero;
        Quaternion rotDesired = Quaternion.identity;

        switch (camMode)
        {
        case eCamMode.far:
            pDesired   = playerInstance.transform.position + relativePosFar;
            rotDesired = Quaternion.Euler(xRotationFar, 0, 0);
            break;

        case eCamMode.nearL:
        case eCamMode.nearR:
            // This will be added by learners later.
            break;
        }

        Vector3 pInterp = (1 - cameraEasing) * transform.position + cameraEasing * pDesired;

        transform.position = pInterp;

        Quaternion rotInterp = Quaternion.Slerp(transform.rotation, rotDesired, cameraEasing);

        transform.rotation = rotInterp;
    }