custom follow script choppy movement

Hi, I made a little follow script for a flying game and it works just fine, however camera movement gets rather choppy. I can lower the smooth parameter to make it less choppy, but doing so means the camera will follow way to slow. Does anyone know of a way to fix this choppyness?

Here’s my current script:

#pragma strict
var player: GameObject;
var target : Transform; //this is a node behind my aircraft, not the same as player...
var oldPos: Vector3;
var newPos: Vector3;
var smooth: float = 5;

function Awake()
{
 player = GameObject.FindWithTag("Player");
 oldPos = transform.position;
 newPos = target.position;
}

function LateUpdate()
{
    oldPos = transform.position;
    transform.rotation = player.transform.rotation;
    transform.position = Vector3.Lerp(oldPos, newPos,Time.deltaTime * smooth);
 newPos = target.position;
}

You should smoothen your rotation too. The choppy effect probably comes from the fact that you’re setting the rotation hard each frame.

Just use that Lerp with smoothing on your rotation too.

Example

transform.rotation = Quaternion.Lerp(transform.rotation, player.transform.rotation, Time.deltaTime * smooth);

I would suggest something else for your position smoothing…

You can also do:

transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * smooth);

By further tweaking your smooth variable, combined with your rotation smoothing, you should get a better result.

Please let me know if that helped.