I’ve created a fairly simple mouse-look script for an fps game i’m working on, however I’ve noticed that while the mouse movement appears smooth, whenever I strafe around objects I get this annoying jittery look on objects that I focus on. Can someone take a look at my code, and tell me how I might improve it?
public class PlayerLook : MonoBehaviour
{
public float mouseSensitivity = 100.0f;
public float clampAngle = 80.0f;
private float mouseX;
private float mouseY;
private float rotationX = 0.0f;
private float rotationY = 0.0f;
void Start()
{
Vector3 rotation = transform.localRotation.eulerAngles;
rotationX = rotation.x;
rotationY = rotation.y;
}
void Update()
{
mouseX = Input.GetAxis("Mouse X");
mouseY = Input.GetAxis("Mouse Y");
rotationX += mouseY * mouseSensitivity * Time.deltaTime;
rotationY += mouseX * mouseSensitivity * Time.deltaTime;
rotationX = Mathf.Clamp(rotationX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotationX, rotationY, 0.0f);
transform.rotation = Quaternion.Lerp(transform.rotation, localRotation, Time.fixedTime);
}
}