Search Unity

Question Camera Stuttering in Unity 2021

Discussion in 'Editor & General Support' started by Deleted User, Aug 5, 2022.

  1. Deleted User

    Deleted User

    Guest

    I'm making a first person game and whenever I rotate the camera it stutters and looks like I am getting a low frame rate, but there is almost nothing in my scene and my fps is above 500. This is only in Unity 2021, it works fine in 2020 and 2019 versions. It also works fine without the universal render pipeline.
    Here is my camera script:
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. public class CameraScript : MonoBehaviour
    6. {
    7.     public GameObject player;
    8.     public float mouseSensitivity;
    9.     Vector2 rotation;
    10.  
    11.     void Start()
    12.     {
    13.         mouseSensitivity = 2f;
    14.     }
    15.  
    16.     void Update()
    17.     {
    18.         float xAxisRot = Input.GetAxisRaw("Mouse Y");
    19.         float yAxisRot = Input.GetAxisRaw("Mouse X");
    20.         rotation.x += xAxisRot * mouseSensitivity;
    21.         rotation.y += yAxisRot * mouseSensitivity;
    22.         rotation.x = Mathf.Clamp(rotation.x, -90f, 90f);
    23.         player.transform.rotation = Quaternion.Euler(0, rotation.y, 0);
    24.         transform.localRotation = Quaternion.Euler(rotation.x, 0, 0);
    25.     }
    I've already tried multiplying it by Time.deltaTime but that didn't fix it.
     
  2. spiney199

    spiney199

    Joined:
    Feb 11, 2021
    Posts:
    7,934
    Usually you want to update cameras in LateUpdate, so that it's not fighting with anything else being altered in Update.

    Also you may want to look at Cinemachine which provides camera stuff like this out of the box.
     
  3. Deleted User

    Deleted User

    Guest

    I tried both of those things but they didn't fix it. I think I'll just keep using Unity 2020 because I haven't had any problems with it.