Smooth Camera Vertical Follow

Hello All,

I’ve got what I thought was quite a simple camera follow script. But alas it’s not working perfectly.

The plan is to follow my hero (an asteroid), smoothly downwards as it travels downwards. The camera only goes downwards (there’s not turning around) and only travels down the Y axis.

I thought I’d simply check how far past the centre the hero was and start panning downwards relatively. SImple. As the camera moves down it catches up with the hero and therefore creates its own ease.

At first it seems to be working fine, but once things get fast, or once I increase the modifier (which basically works to set the speed at which it catches up), it starts to jitter. This jitter gets worse the quicker you’re going.

Is there a better way to do this? Or is there something obviously wrong with my code?

  void LateUpdate () {
    	Vector3 targetPos = camera.WorldToViewportPoint(target.transform.position);
            // Calculate distance from centre and affect Transform
    	float velocity = (targetPos.y - 0.5f) * modifier;
    	velocity = Mathf.Min(0, velocity);
    	transform.Translate(0, Time.deltaTime*velocity, 0);

I don’t know if this is any less jittery, but here is an alternate:

public class TrackOnY : MonoBehaviour {
	public Transform target;
	public float speed = 1.0f;
	void LateUpdate () {
        Vector3 v3 = transform.position;
		v3.y = Mathf.Lerp (v3.y, target.position.y, Time.deltaTime * speed);
		transform.position = v3;