# Switch Smooth Follow between targets smoothly

I have a Smooth Follow script on my main camera. This works fine. Now, I would like to switch between two targets and have the camera move smoothly between the two target and then resume following the second target. How might I accomplish this? I have tried Lerping between the two and that did not seem to work but I may just be doing it wrong. Thanks…

I’m not happy with the code below, but it is all I have time for at the moment. It’s based on the standard Smooth Follow. You need to Lerp() both the position and the LookAt rotation in order to get the smooth movement you want. Of course this will impact the general movement. Try it an let me know. There is another way to approach the problem (that does not involve modifying SmoothFollow).

``````var target : Transform;
var distance = 10.0;
var height = 5.0;
var rotationDamping = 3.0;
var movementDamping = 1.0;

function LateUpdate () {
if (!target)
return;

var wantedHeight = target.position.y + height;
var currentRotationAngle = transform.eulerAngles.y;
var currentHeight = transform.position.y;

currentRotationAngle = target.eulerAngles.y;

var currentRotation = Quaternion.Euler (0, currentRotationAngle, 0);

var pos = target.position;
pos -= currentRotation * Vector3.forward * distance;
pos.y = wantedHeight;

transform.position = Vector3.Lerp(transform.position, pos, movementDamping * Time.deltaTime);

var q = Quaternion.LookRotation(target.transform.position - transform.position, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, q, rotationDamping * Time.deltaTime);
}
``````