コード例 #1
0
    public void UpdateCamera()
    {
        lerpTimer += Time.deltaTime;
        if (ship.GetInputState() != lastState)
        {
            lastState   = ship.GetInputState();
            lerpTimer   = 0f;
            endPos      = target.transform.position;
            endRotation = target.transform.rotation;
            switch (lastState)
            {
            case Ship.State.playerInputs:
                break;

            case Ship.State.playerRollLeft:
                break;

            case Ship.State.playerRollRight:
                break;

            case Ship.State.playerTurnDown:
                up      = ship.transform.up;
                forward = ship.transform.forward;
                right   = ship.transform.right;
                break;

            case Ship.State.playerTurnUp:
                up      = ship.transform.up;
                forward = ship.transform.forward;
                right   = ship.transform.right;
                break;

            default:
                break;
            }
        }

        if (target != null && ship != null)
        {
            switch (lastState)
            {
            case Ship.State.playerInputs:
                target.transform.position = ship.transform.position + ship.transform.up * 4.25f /* * ship.Throttle*/;
                target.transform.rotation = Quaternion.Lerp(endRotation, ship.transform.rotation, 4f * (lerpTimer / LERP_TIME) * (lerpTimer / LERP_TIME));
                break;

            case Ship.State.playerRollLeft:
                target.transform.position = Vector3.Lerp(endPos, ship.transform.position + ship.transform.up * 4.25f /* * ship.Throttle*/, 4f * lerpTimer / LERP_TIME);
                break;

            case Ship.State.playerRollRight:
                target.transform.position = Vector3.Lerp(endPos, ship.transform.position + ship.transform.up * 4.25f /* * ship.Throttle*/, 4f * lerpTimer / LERP_TIME);
                break;

            case Ship.State.playerTurnDown:
                target.transform.position = ship.transform.position + up * 4.25f /* * ship.Throttle*/;
                target.transform.forward  = forward * Mathf.Cos(Mathf.PI * lerpTimer / 0.58f) + right * Mathf.Sin(Mathf.PI * lerpTimer / 0.58f);
                break;

            case Ship.State.playerTurnUp:
                target.transform.position = ship.transform.position + up * 4.25f /* * ship.Throttle*/;
                target.transform.forward  = forward * Mathf.Cos(Mathf.PI * lerpTimer / 0.58f) - right * Mathf.Sin(Mathf.PI * lerpTimer / 0.58f);
                break;

            default:
                break;
            }
            if (mainCamera != null)
            {
                if (ship.GetInputState() == Ship.State.playerInputs)
                {
                    if (Input.GetButton("PushRight"))
                    {
                        mainCamera.GetComponent <Cinemachine.CinemachineVirtualCamera>().enabled = false;
                    }
                    else
                    {
                        mainCamera.GetComponent <Cinemachine.CinemachineVirtualCamera>().enabled = true;
                    }
                }
                else
                {
                    mainCamera.GetComponent <Cinemachine.CinemachineVirtualCamera>().enabled = true;
                }
            }
        }
    }
コード例 #2
0
 public void setState(Ship.State state)
 {
     this.state = state;
 }