i used this code for it and the cam just spazed out
using System.Collections;
using System.Collections.Generic;
using Unity.PlasticSCM.Editor.WebApi;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.UIElements;
public class player_cam : MonoBehaviour
{
public bool isActive = true;
public float mouseSensitivity = 100f; // Sensitivity for mouse movement
public Transform playerBody; // Reference to the player’s body (the GameObject with the Rigidbody)
public Transform cameraTransform; // Reference to the camera
public Rigidbody playerRigidbody; // Reference to the player’s Rigidbody
public float moveSpeed = 5f; // Movement speed
private float xRot = 0f;
private float yRot = 0f; // Track the camera's vertical rotation
void Start()
{
// Lock and hide the cursor
UnityEngine.Cursor.lockState = CursorLockMode.Locked;
UnityEngine.Cursor.visible = false;
}
void Update()
{
if (isActive) {
xRot+=Input.GetAxis("Mouse Y");
yRot+=Input.GetAxis("Mouse X");
xRot += Mathf.Clamp(xRot, -90f, 90f);
yRot += Mathf.Clamp(yRot, -180f, 180f);
Camera.main.transform.rotation = Quaternion.Euler(xRot/moveSpeed,yRot/moveSpeed,z:0f);
UnityEngine.Cursor.visible = !isActive;
}
if (Input.GetKeyDown(KeyCode.Escape)) {
isActive = !isActive;
}
}
}