FPS camera jitters while moving and turning
I have been stumped for days on this. I'm writing a simple FPS controller and using mouse look. Mouse y rotates the first person camera's x axis to look up and down. Mouse x is supposed to simply rotate the player but no matter how I set it up, it jitters but ONLY while I am running forward. I can rotate smoothly until I start moving at the same time. Both the camera and player are rotating in Update as well. Any kind of solution to do this setup smoothly would be extraordinarily helpful. It is also worth noting that the camera is a child of the player (so that it rotates with the player to look left and right)
This is how the player rotates:
public class PlayerRotation : MonoBehaviour
{
public float sensitivity = 1.0F;
public float smoothing = 1.0F;
float rotationY = 0F;
float smoothedY = 0F;
void Update()
{
rotationY += Input.GetAxisRaw("Mouse X") * sensitivity;
smoothedY = Mathf.Lerp(smoothedY, rotationY, 1.0F / smoothing);
transform.localEulerAngles = new Vector3(0.0f, smoothedY, 0.0f);
}
}
This is how the camera rotates:
public class MouseLook_1P : MonoBehaviour
{
public float sensitivity = 1.0F;
public float smoothing = 1.0F;
private float minimumX = -80F;
private float maximumX = 80F;
float rotationX = 0F;
float smoothedX = 0F;
void Update()
{
rotationX += Input.GetAxisRaw("Mouse Y") * sensitivity;
rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
smoothedX = Mathf.Lerp(smoothedX, rotationX, 1.0F / smoothing);
transform.localEulerAngles = new Vector3(-smoothedX, 0.0f, 0.0f);
}
private void OnApplicationFocus(bool focus)
{
if (focus) { Cursor.lockState = CursorLockMode.Locked; }
else { Cursor.lockState = CursorLockMode.None; }
}
}
Why do they not sync up correctly and why does it feel like I'm losing frames as I look around while moving despite being able to independently move or rotate completely smoothly?
Your answer
Follow this Question
Related Questions
Camera rotate X degree based on player rotate 0 Answers
My player doesn't rotate at the same time with the camera. 0 Answers
Rotate Unity3D FirstPersonCamera with values from Arduino in form of -127 to 127 (degrees) … 0 Answers
Camera RotateAround, in different angles it moves X instead of Y 0 Answers