Laggy Camera

Hello!

I recently changed my camera script, and the new one is really laggy.

Here is the script:

using UnityEngine;
using System.Collections;

public class CarCamera : MonoBehaviour
{
		[SerializeField]
		private float distanceAway;
		[SerializeField]
		private float distanceUp;
		[SerializeField]
		private float smooth;
		[SerializeField]
		private Transform follow;
		private Vector3 targetPosition;

	void Start() {
		follow = GameObject.FindWithTag ("Player").transform;
	}

	void OnDrawGizmos () {

	}
	
		void LateUpdate ()
		{
		targetPosition = follow.position + follow.up * distanceUp - follow.forward * distanceAway;
		Debug.DrawRay (follow.position, Vector3.up * distanceUp, Color.red);
		Debug.DrawRay (follow.position, -1f * follow.forward * distanceAway, Color.blue);
		Debug.DrawLine (follow.position, targetPosition, Color.magenta);

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

		transform.LookAt (follow);

		}
}

And here is the inspector:

40998-screen-shot-2015-02-18-at-213136.png

I’d recommend usingSmoothDamp
As it gives you control of how fast the camera “springs” towards the car like a rubber band.

Read about Lerp again. t needs to be a value interpolating from 0 to 1. You used Time.deltaTime * smooth as a value, which is a very jittery constant somewhere near 0 (e.g.: 0.05 times 4 = 0.2)

Hi!

Change LateUpdate () function to FixedUpdate() and probably it’s work.