I’ve found other answers, but they are simply not working with my code. I’m a beginner, so I’m probably just not doing it right. Here is my code:
using UnityEngine;
using System.Collections;
public class FirstPersonCamera : MonoBehaviour {
public bool lockCursor;
public float mouseSensitivity = 10;
public Vector2 pitchMinMax = new Vector2 (-27, 50);
public float rotationSmoothTime = .12f;
Vector3 rotationSmoothVelocity;
Vector3 currentRotation;
float yaw;
float pitch;
void Start() {
if (lockCursor) {
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
}
void LateUpdate () {
yaw += Input.GetAxis ("Mouse X") * mouseSensitivity;
pitch -= Input.GetAxis ("Mouse Y") * mouseSensitivity;
pitch = Mathf.Clamp (pitch, pitchMinMax.x, pitchMinMax.y);
currentRotation = Vector3.SmoothDamp (currentRotation, new Vector3 (pitch, yaw), ref rotationSmoothVelocity, rotationSmoothTime);
transform.eulerAngles = currentRotation;
}
}