I am using this script for player movement and camera movement, and for some reason its really choppy when looking left or right.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class player : MonoBehaviour
{
Transform cam;
Rigidbody rb;
public float speed, mouseSensitivity, maxspeed;
public bool grounded;
float xRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
rb = GetComponent<Rigidbody>();
cam = Camera.main.transform;
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxis("Horizontal");
float z = Input.GetAxis("Vertical");
rb.AddForce(transform.forward * z * speed, ForceMode.VelocityChange);
rb.AddForce(transform.right * x * speed, ForceMode.VelocityChange);
rb.velocity = new Vector3 (Mathf.Clamp(rb.velocity.x, -maxspeed, maxspeed), rb.velocity.y, Mathf.Clamp(rb.velocity.y, -maxspeed, maxspeed));
if(x == 0 && z == 0)
{
rb.velocity = rb.velocity * 0.99f;
}
camMove();
}
//camera movement
void camMove()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
transform.Rotate(transform.up, mouseY);
xRotation -= mouseY;
xRotation = Mathf.Clamp(xRotation, -90f, 90f);
cam.transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
}
}