- Home /
Jittery FPS Camera when moving
I'm writing a basic FPS controller and using the following for mouse look:
public float sensitivity = 1.0F;
public float smoothing = 1.0F;
private float minimumX = -80F;
private float maximumX = 80F;
float rotationX = 0F;
float rotationY = 0F;
float smoothedX = 0F;
float smoothedY = 0F;
void Update()
{
rotationX += Input.GetAxisRaw("Mouse Y") * sensitivity;
rotationY += Input.GetAxisRaw("Mouse X") * sensitivity;
rotationX = Mathf.Clamp(rotationX, minimumX, maximumX);
smoothedX = Mathf.Lerp(smoothedX, rotationX, 1.0F / smoothing);
smoothedY = Mathf.Lerp(smoothedY, rotationY, 1.0F / smoothing);
transform.localEulerAngles = new Vector3(-smoothedX, smoothedY, 0.0f);
}
I have been stuck for days trying to get my player to rotate in the camera direction so that they can walk forward based on where you look. I have tried many things and all of them result in either the player not turning, or it "working" but having the camera get choppy whenever I move AND rotate at the same time.
I am moving the player like this:
private void GetInput()
{
vInput = Input.GetAxis("Vertical");
hInput = Input.GetAxis("Horizontal");
jumpInput = Input.GetAxisRaw("Jump");
}
private void Run()
{
vel.z = vInput * speed;
vel.x = hInput * speed;
}
private void Update()
{
GetInput();
Run();
Jump();
rb.velocity = transform.TransformDirection(vel);
}
Can someone please explain to me how to properly do this setup and how to stop the camera jitter? Both the camera and the player are being rotated in Update() so I don't think they should be out of sync in their movements but I must be misunderstanding something.
I tested your scripts and it worked for me. Good examples for FPS-controller are in the StandardAssets.
Try move rb.velocity = transform.TransformDirection(vel);
to FixedUpdate().
Answer by EagleDeveloper · Aug 07, 2020 at 08:10 PM
Hey @SecurityOstrich ,
Sorry for the late Reply
Actually, I had the same problem, It actually is very simple.
Just change this:
rotationX += Input.GetAxisRaw("Mouse Y") * sensitivity * Time.fixedDeltaTime;
rotationY += Input.GetAxisRaw("Mouse X") * sensitivity * Time.fixedDeltaTime;
I made an account just to thank you for saving my game. Thank you brother Time.deltatime did not work but Time.FixedDetlaTime did Thank you and have a good life.
Your answer
Follow this Question
Related Questions
Jittery camera motion in GearVR when moving camera - nothing seems to work. 2 Answers
Movement jitter every few seconds 1 Answer
First Person Player 3 Answers
FPS controller and mouseLook problem 1 Answer