- Home /
Camera Shaking At High Speed
Hello,
Im in the middle of making a space sim, But i seem to be having problems with the camera, It follows the ship and pulls away from the ship as the ship gets faster, But when the ship is at max speed the samera seems to shake, At first i thought it might be the ship controller script causing the ship to shake but i guess not, Can someone have a look at this code and see if theres anything wrong? Thanks.
var target : Transform;
var distanceToFollow : float = 5.0;
var height : float = 1.0;
var moveSpeed : float = 1.0;
var rotationSpeed : float = 1.0;
private var targetRay : Ray;
function Update () {
//move the camera into position behind the target
targetRay = new Ray(target.position,-target.forward);
point = targetRay.GetPoint(distanceToFollow);
point = Vector3.Slerp(transform.position, point, Time.deltaTime * moveSpeed);
transform.position = point;
//rotate the camera to match the rotation of the target
transform.LookAt(target,target.up);
}
Answer by TowerOfBricks · May 25, 2012 at 02:47 PM
This is probably because first, your camera object adjusts its rotation to look at the object, then your object moves a tiny bit in its update step, next the scene is rendered, now the camera will not look exactly at the object since it moved a bit. To solve this, put the camera updating code in LateUpdate instead of Update.
I changed it around a bit and put it in the LateUpdate function and it didn't seem to change anything, If anything it seemed to make things worse, Are cameras not supposed to move at high speed?
Try removing that Slerp call and see if it makes it better. In high speeds that might cause things to vibrate because of different Time.deltaTime values (I think at least).
I removed the Slerp and it made no difference, Dose everything seem ok to you in the script i posted? Or is there a better way to do it?
Problem solved, Aron Granberg told me to change the function Update to LateUpdate And it didnt solve the problem, So i though i might aswell try the FixedUpdate function and it seems to have solved the problem. As smooth as it can get. Thanks.
Aron Granberg can you edit your answer to FixedUpdate so i can mark it as a correct answer, Thanks.
Thank you! It solved my problem too.
$$anonymous$$y situation is.. when using follow-came(setting camera directly to a location), camera did not shake. But camera for mirror is shaking. (so the image in the mirror is shaking simultaneously)
I tried it again. Update velocity of rigid body in method "FixedUpdate", then update follow camera in method "LateUpdate". And interpolate can not be null. it works too.
Your answer
Follow this Question
Related Questions
Weird Camera Follow Problem 1 Answer
Rotate spaceship based on mouse movement 2 Answers
Camera following Pivot not working 1 Answer
3rd Person Camera Problem 1 Answer
Weapons Range Projectile script 1 Answer