c# - Camera jitters when rotating but not moving - Stack Overflow

admin2025-04-17  3

My camera rotates whenever I rotate it, I am not sure why, I have tried many solutions including: multiplying by time.deltatime, dividing by time.deltatime, trying all variations of update void, I also tried to get mathf.smoothdampenangle to work but I couldn't figure out how to make the float change to a quaternion. I have set interpolation to interpolate.

Here is my code for my FPS characters camera:

{

// Variables
public Transform player;
public Transform rotatePoint;
public float mouseSensitivity = 2f;
float cameraVerticalRotation = 0f;
float velocity = 1f;

//bools
bool lockedCursor = true;

void Start()
{
    // Lock and Hide the Cursor
    Cursor.visible = false;
    Cursor.lockState = CursorLockMode.Locked;
}


void FixedUpdate()
{
    
    // Collect Mouse Input

    float inputX = Input.GetAxisRaw("Mouse X") * mouseSensitivity;
    float inputY = Input.GetAxisRaw("Mouse Y") * mouseSensitivity;

    // Rotate the Camera around its local X axis

    cameraVerticalRotation -= inputY;
    cameraVerticalRotation = Mathf.Clamp(cameraVerticalRotation, -90f, 90f);
    transform.localEulerAngles = Vector3.right * cameraVerticalRotation;
    // Rotate the Player Object and the Camera around its Y axis
    player.Rotate(Vector3.up * inputX);
}

}

I suspect the cause for the jitter is that my camera is rotating in set amounts of degrees instead of rotating smoothly.

转载请注明原文地址:http://www.anycun.com/QandA/1744892759a89109.html