- Home /
Jittery thid-person camera follow behaviour
I'm writing a controller script for a floating UFO-like ship that behaves somewhat like a helicopter, but is not affected by gravity.
The control script for the ship looks like this:
void FixedUpdate()
{
vertical = Input.GetAxis("Vertical");
horizontal = Input.GetAxis("Horizontal");
forward = Input.GetAxis("Forward");
rigidbody.rotation = Quaternion.Lerp(rigidbody.rotation, Quaternion.LookRotation(myCamera.forward, myCamera.up), Time.deltaTime * rotateSpeed);
rigidbody.AddForce(transform.up * vertical * verticalSpeed);
rigidbody.AddForce(transform.right * horizontal * horizontalSpeed);
rigidbody.AddForce(transform.forward * forward * forwardSpeed);
}
Which is simply:
Space/Ctrl to move the ship up and down
W/S to move the ship forwards and backwards
A/D to strafe the ship left and right.
And I have a Third person camera object (from the Sample Assets Beta package from the Asset store) following and tracking my ship.
The ship controls perfectly fine, however when viewing the game from the Game view, Forwards, Backwards, and strafing left and right seems to work fine, however rotating the ship seems to cause the ship to look 'Jittery'. As far as I can see the jitter doesn't happen on the ship, but on the camera, as viewing the ship rotate in the Scene view doesn't look like it's jittering.
As you can see, the Rotation is happening in FixedUpdate. The Third Persona camera prefab has an option to set the Update type for FixedUpdate or LateUpdate. I have chosen FixedUpdate as it seems to work better (LateUpdate has even worse jittering)
Any ideas, what can I try here to try and solve this?
I'd also appreciate any comments for the way I've implemented the controller script - is this an O$$anonymous$$ way to do this? Is there a better way? The script does not appear in the Profiler at all when running the game, so I assume it is not not a terrible algorithm
Your answer
Follow this Question
Related Questions
Camera update when tracking physics controlled object 0 Answers
Camera parenting to rigidbody 0 Answers
Smart camera? 1 Answer
How do I make a third person camera toggle that doesn't snap? 0 Answers