Problem with SmoothDamp/Lerp camera

I decided to make smoother camera using interpolation, but it ended up being worse than simple cam.pos = player.pos.
Here goes the code and the video of “stuttering” in the movement after certain distance traveled. What am i doing wrong?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CameraFollow : MonoBehaviour {

    // Use this for initialization
    [SerializeField] private Transform target;
	void Start () {
        
	}
	

    void LateUpdate()
    {
        transform.position = Vector3.Lerp(transform.position, target.position, 0.1f);
    }
}

Increase your .1f to something like 5f. That should smooth it out. But take a look at the Unity docs on Vector3.Lerp. Might help you even further…

I had been looking for this as well, and it turns out that Lerp() is supposed to be used with a fixed source/destination, so with a moving target the result is not good, and we shoud use SmoothDamp() instead:

public class CameraFollow : MonoBehaviour {

	[SerializeField] float smoothSpeed = 0.5f;
	Vector3 velocity = Vector3.zero; // Called by reference in SmoothDamp()
	GameObject player;

	void Start () 
	{
		player = GameObject.FindGameObjectWithTag("Player");
	}

	void LateUpdate() 
	{
		transform.position = Vector3.SmoothDamp(transform.position, player.transform.position, ref velocity,  smoothSpeed);
	}
}

Result:

My script.
I have used 2 metods, but decide for the most simple.

Privacy & Terms