I cant for the life of me figure out why but my camera script runs fine, until I hit a small object then it starts rotating continuously in either left or right. Feel I should also mention Im very new to coding and unity and this code was from a video.
This is the camera script if the problem lies in here.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MouseLook : MonoBehaviour
{
public float mouseSens;
public Transform playerBody;
float xRot = 0f;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSens * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSens * Time.deltaTime;
xRot -= mouseY;
xRot = Mathf.Clamp(xRot, -90f, 90f);
transform.localRotation = Quaternion.Euler(xRot, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}