# How to rotate a camera slowly along a tween?

So i have a camera on a tween that loops around 2 rooms, when the camera enters a room it focuses on the target i set in that room, the problem is it’s not smooth at all, i’ve found examples using quaternion with one object or on key presses but can’t understand how to do it automaticaly.

Here’s the code it’s not much, very simple.

``````if (transform.position.z < 17.16)
{
transform.LookAt(target1);

}
else
{
transform.LookAt(target2);
}
``````

I’d just like to know what to add or change to give it a slow rotation speed that may stop all the juddering.

I’d create five parameters in the script, private boolean turning, private float time, private Vector3 initial, private Vector3 final, and private Vector3 disp.
Then in the start function, set turning to false and seconds to however much time you want (although depending on what function you’re running the whole thing in, the time might not be frame-rate independent, so watch out).

Finally, replace transform.LookAt with this code:

``````if (!turning){
initial = transform.forward;
final = target1.position - transform.position;
disp = ((final.x-initial.x)/time, (final.y-initial.y)/time, (final.z-initial.z)/time);
turning = true;
transform.Rotate(disp);
} else{
transform.Rotate(disp);
if (Mathf.Abs(transform.forward-final).x < Mathf.Abs(disp).x || Mathf.Abs(transform.forward-final).y < Mathf.Abs(disp).y || Mathf.Abs(transform.forward-final).z < Mathf.Abs(disp).z){
transform.LookAt(target1);
}
}
``````

Assuming you run this in some sort of every tick method (e.g. update), it should work.