using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraController : MonoBehaviour
{
private GameObject player;
private float speedH = 2.0f;
private float speedV = 2.0f;
private float yaw = 0.0f;
private float pitch = 0.0f;
private void Awake() {
Cursor.lockState = CursorLockMode.Locked;
player = transform.parent.gameObject;
}
private void Update() {
Cursoru();
}
private void Cursoru() {
yaw += speedH * Input.GetAxis("Mouse X");
pitch -= speedV * Input.GetAxis("Mouse Y");
transform.eulerAngles = new Vector3(Mathf.Clamp(pitch, -45f, 45f);, yaw, 0.0f);
player.transform.eulerAngles = new Vector3(0.0f, yaw, 0.0f);
}
}
When I run the code I can rotate the camera correctly and so on. But if I keep moving the mouse up or down, and then I want to look in the opposite direction, I have to move it a lot so it actually rotates the camera. I don’t get any error in console so I don’t know what I can do to solve that bug.