Hello,
I am having very annoying issues with my camera. I have been searching for a solution for quite a while now and I have finally decided to post here about it. Anyways, the issue is that occasionally I get these weird jitters when I move my camera. It is smooth for a second, but randomly the camera will skip a few degrees in rotation. The camera is for my Player in the style of FPS. The Player is a rigidbody not a character controller. I have tried different solutions such as making it a child of the player, making it separate with a follow script, switching between LateUpdate and Update, all to no avail. It is not like the common problem I found for others where whenever the player moved other objects would jitter, rather it is an issue with the rotation of the camera itself. I appreciate anyone attempting to help me.
Here is the script, which is very basic.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerCamera : MonoBehaviour
{
public float MouseSensativity = 500f;
public Transform playerBody;
float xRotation = 0f;
float yRotation = 0f;
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void LateUpdate()
{
float mouseX = Input.GetAxis("Mouse X") * MouseSensativity*Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * MouseSensativity*Time.deltaTime;
xRotation -= mouseY;
yRotation += mouseX;
xRotation = Mathf.Clamp(xRotation, -90, 90f);
transform.localRotation = Quaternion.Euler(xRotation, yRotation, 0f);
playerBody.Rotate(Vector3.up * mouseX);
}
}