FPS Camera infinitely spins without applying any mouse input,FPS Camera rotates uncontrollably without me even moving my mouse. It starts spinning on both the x and y axis.

I’m relatively inexperienced, so I followed a tutorial to create this code, but as described, the camera spins automatically without applying any directional input from my mouse.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MouseLook : MonoBehaviour
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation = 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") + mouseSensitivity * Time.deltaTime;
    float mouseY = Input.GetAxis("Mouse Y") + mouseSensitivity * Time.deltaTime;

    xRotation -= mouseY;
    xRotation = Mathf.Clamp(xRotation, -90f, 90f);
    transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
    playerBody.Rotate(Vector3.up * mouseX);


This line:

float mouseX = Input.GetAxis("Mouse X") + mouseSensitivity * Time.deltaTime;

should be

float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;

It’s the same for the mouseY line.
Note the * instead of the +. Also if you are still learning you should focus on understanding what you’re actually doing. Your mouseX and mouseY values are used to rotate your player relatively. So a positive value will rotate one way, a negative value will rotate the other way round. A value of 0 will not rotate at all. So if there is no delta input (so GetAxis returns 0) you want mouseX / mouseY to be 0. Of course when adding two values together the result can only be 0 when both are 0 (or when the cancel each other perfectly). Both cases will probably never happen in your case. You actually want to “scale” / multiply the incoming input value by the sensitivity and deltaTime. When you multiply multiple value together the result will be 0 whenever any of those values is 0.

So this is more of a logic issue and not really unity specific. If you copied this code from a tutorial or something you probably have confused those * with +. Please do not use tutorials as a template source to copy&paste from. Tutorials are there to teach you how to achieve a certain goal. So your main concern should be to understand the code.