- Home /
How do i fix choppy camera follow?,Choppy camera follow
I'm doing this course: https://learn.unity.com/tutorial/lesson-1-4-use-user-input-to-control-the-vehicle?uv=2018.4&courseId=5cf96c41edbc2a2ca6e8810f≺ojectId=5caccdfbedbc2a3cef0efe63#5cbe3969edbc2a191e639152
So I'm on a kind of old Mac and the camera is really choppy. Heres my code: using System.Collections; using System.Collections.Generic; using UnityEngine;
public class FollowPlayer : MonoBehaviour { public GameObject player; private Vector3 offset = new Vector3(0, 5, -7);
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
//Offset the camera behind the player by adding to the player’s position
transform.position = player.transform.position + offset;
}
}
What can I do to fix it?
Answer by highpockets · Dec 09, 2020 at 08:31 AM
It is good practice to put camera follow code in LateUpdate() as it is called at the end of the Game Logic after all animations and other game logic is calculated and just before the render calculations. That might help, but if it doesn’t cure the situation, you might want to looking into SmoothDamp. It is a typical camera follow behaviour that helps to smooth out camera movements: (though SmoothDamp() for the camera should also go in LateUpdate())
public class ExampleClass : MonoBehaviour
{
public Transform target;
public float smoothTime = 0.3F;
private Vector3 velocity = Vector3.zero;
void LateUpdate()
{
// Smoothly move the camera towards that target position
transform.position = Vector3.SmoothDamp(transform.position, target.position, ref velocity, smoothTime);
}
}