Last active
March 2, 2020 11:40
-
-
Save reneweiser/86b06b08a42383dbd7bfb0d3a4d274bc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
public class BasicFpCamera : MonoBehaviour | |
{ | |
[SerializeField] private Camera _camera; | |
[SerializeField] private Transform _body; | |
[SerializeField] private float _pitchMin = -60f; | |
[SerializeField] private float _pitchMax = 60f; | |
[SerializeField] private float _sensitivity = 2f; | |
private float _pitchDelta = 0f; | |
private float _yawDelta = 0f; | |
private void Update() | |
{ | |
_pitchDelta += Input.GetAxis("Mouse Y") * _sensitivity; | |
_yawDelta += Input.GetAxis("Mouse X") * _sensitivity; | |
_pitchDelta = Mathf.Clamp(_pitchDelta, _pitchMin, _pitchMax); | |
_camera.transform.localEulerAngles = new Vector3(-_pitchDelta, 0f, 0f); | |
_body.eulerAngles = new Vector3(0f, _yawDelta, 0f); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment