Question by
threefiregamez · Oct 29, 2020 at 06:13 AM ·
unity 5cameracamera follow
Jittery Camera Follow Lerp
Im using a camera follow for my third person character. The problem is I'm getting a little jitter here and there. Any help would be much appreciated...
public class dg_simpleCamFollow : MonoBehaviour
{
public Transform target;
[Range(1f,40f)] public float laziness = 11f;
public bool lookAtTarget = true;
public bool takeOffsetFromInitialPos = true;
public Vector3 generalOffset;
Vector3 whereCameraShouldBe;
bool warningAlreadyShown = false;
private void Start() {
if (takeOffsetFromInitialPos && target != null) generalOffset = transform.position - target.position;
}
void FixedUpdate()
{
if (target != null) {
whereCameraShouldBe = target.position + generalOffset;
transform.position = Vector3.Lerp(transform.position, whereCameraShouldBe, 1 / laziness);
if (lookAtTarget) transform.LookAt(target);
} else {
if (!warningAlreadyShown) {
Debug.Log("Warning: You should specify a target in the simpleCamFollow script.", gameObject);
warningAlreadyShown = true;
}
}
}
}
Comment