Question by
Blueknight1758 · Feb 03, 2016 at 03:13 AM ·
controllercamera-movement
Jiggling Camera
Hey i'm trying to create a spaceflight game and have found a camera script that's perfect except it 'jiggles' when following an object.
Script originally from: http://answers.unity3d.com/questions/20172/space-game-camera.html
var target : Transform;
var distance = 3.0;
var height = 3.0;
var damping = 5.0;
var smoothRotation = true;
var rotationDamping = 10.0;
function Update () {
var wantedPosition = target.TransformPoint(0, height, -distance);
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping);
if (smoothRotation) {
var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up);
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping);
}
else transform.LookAt (target, target.up);
}
The link suggested above says someone encountered the same issue and fixed it by adding 'time.deltaTime' but my object is controlled by rigidbody forces so I don't know how to do that.
Movement Script:
function FixedUpdate () {
var roll = Input.GetAxis("Horizontal");
rb.AddTorque(transform.forward * torque * -roll);
var pitch = Input.GetAxis("Vertical");
rb.AddTorque(transform.right * torque * pitch);
rb.AddForce(transform.forward * thrust * 2 * boost );
}
How would I stop the 'Jiggling' or add time.deltatime to my script?
Comment
Best Answer
Answer by Blueknight1758 · Feb 03, 2016 at 12:38 PM
I've managed to fix the problem, the object the camera was following was using FixedUpdate() whilst the camera was using Update(). Setting both to FixedUpdate() appears to of fixed the issue.