revival/game/Assets/Scripts/Camera/CameraController.cs

43 lines
1.1 KiB
C#
Raw Permalink Normal View History

2021-01-27 13:06:17 +01:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
2021-03-01 19:03:30 +01:00
using Cinemachine;
2021-01-27 13:06:17 +01:00
public class CameraController : MonoBehaviour
{
[SerializeField]
private CameraSettings _settings;
[SerializeField]
private PlayerInputHandler _inputHandler;
private Vector2 _cameraRotation;
void FixedUpdate()
{
float deltaTime = Time.fixedDeltaTime;
_cameraRotation += _inputHandler.InputState.Look * ( deltaTime * _settings.LookSpeed );
_cameraRotation.y = Mathf.Clamp( _cameraRotation.y, _settings.LookYMin, _settings.LookYMax );
_inputHandler.SetCameraRotation(_cameraRotation.x * -180.0f);
}
private void LateUpdate()
{
if ( _cameraRotation.x > 1.0f )
{
_cameraRotation.x -= 2.0f;
}
else if ( _cameraRotation.x < -1.0f )
{
_cameraRotation.x += 2.0f;
}
Quaternion rot = Quaternion.Euler( _cameraRotation.y * 180.0f, _cameraRotation.x * 180.0f, 0f );
Vector3 pos = rot * ( Vector3.back * _settings.LookDistance );
transform.localPosition = pos;
transform.rotation = rot;
}
}