- Home /
Choppy Camera Follow
Hi, I'm using a custom sidescroller script and am getting extremely choppy camera movement. I know many people have had this issue, and I've been trying all kinds of suggestions with no luck. My script:
void Start ()
{
origDist = distance;
}
void Update ()
{
if (target)
{
if (Input.GetKey(KeyCode.LeftControl))
distance = origDist * 5;
else
distance = origDist;
Vector3 targetPos = target.position + Vector3.up * extraHeight;
targetPos.z = -distance;
transform.position -= (transform.position - targetPos) * 0.25f;
}
}
I've tried FixedUpdate and LateUpdate as well. How can I get this script to smoothly follow a normal character controller? Thanks!
A quick and easy way to make your camera follow the player, is to make the camera a child of your player object, set the distance manually. Does that work for your needs?
Well it does fix the choppiness issue, but the script I have does more; it sets the camera to follow horizontally like a sidescroller. Parenting causes the camera to rotate with the character. I've been using this script with custom character scripts, but now I've decided to scrap those and build my character from scratch. The previous character scripts did not use a character controller and scripted it's own physics, but now I am using more standard assets...
YES! I kept Update, and set the time to 5.0 and it's silky smooth.
Answer by vexe · Sep 15, 2013 at 05:52 AM
Whenever you're doing any changes to positions inside Update
, multiply by Time.deltaTime
as that will make it time-dependent instead of frame-dependent.
transform.position -= (transform.position - targetPos) * 0.25f * Time.deltaTime;
I know you've mentioned that you've tried the script in FixedUpdate
, but give it a try...
I was struggling with this for a while too. The vexe answer was choppy when I used his code verbatim, but silky smooth when I put it in FixedUpdate().
transform.position -= (transform.position - targetPos) *0.25;
Your answer
![](https://koobas.hobune.stream/wayback/20220613114207im_/https://answers.unity.com/themes/thub/images/avi.jpg)