So I made a script following a tutorial on yt to make a first-person view and movement but I ran into a problem causing my cam to spin around everywhere without my input I’ve tried to find a solution but I couldn’t find one exact to my problem. (also sorry if I didn’t choose the correct prefix)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FirstPersonCam : MonoBehaviour
{
public float sensX;
public float sensY;
public Transform orientation;
float xRotation;
float yRotation;
private void Start()
{
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void Update()
{
//get mouse input
float mouseX = Input.GetAxisRaw(“Mouse X”) * Time.deltaTime * sensX;
float mouseY = Input.GetAxisRaw(“Mouse Y”) * Time.deltaTime * sensY;
yRotation += sensX;
xRotation -= sensY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
//rotate cam and orientation
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
orientation.rotation = Quaternion.Euler(0, yRotation, 0);
}
}