Object seems to stutter when camera following through script, not when attached as child of player.

It’s fenomena known for many years since the days of tycoon transport where a object seems to stutter when camera is following at the same speed…that’s weirder since it doesn’t if childed to player…
It’s a simple sidescroller.
this is my camera follow method. J
p.s. does this thing have a name?

void CamFollowPlayer()
    {
        Vector3 newPos = new Vector3 (player.transform.position.x,player.transform.position.y,this.transform.position.z);
        transform.position = Vector3.Lerp (transform.position, newPos, Speed * Time.deltaTime);
    }

Gets Better When CameraFollow Function Is Also Put In FixedUpdate. But I Think It Makes It Look Like It’s All Lagging. < ?

The cam follow script below usually works fine without stuttering.

using UnityEngine;

public class FollowCam : MonoBehaviour
{
    [SerializeField] private Transform target;
    [SerializeField] private float distance = 5f;

    [SerializeField] private float targetHeightOffset;
    [SerializeField] private float cameraHeightOffset;

    [SerializeField] private float yaw;

    private Vector3 curPos;
    private Camera cam;

    private void Start()
    {
        cam = GetComponent<Camera>();
        curPos = transform.position;
    }

    private void Update()
    {
        Vector3 curPosTmp = curPos;
        Vector3 tgtPos = target.position;

        tgtPos.y = 0.0f;
        curPosTmp.y = 0.0f;

        Vector3 dir2D = curPosTmp - tgtPos;

        float len = dir2D.magnitude;
        dir2D.Normalize();

        Vector3 camPos = curPosTmp;
        if (len > distance)
        {
            camPos = tgtPos + dir2D * distance;
        }

        camPos.y = target.position.y + cameraHeightOffset;
        transform.position = camPos;

        Vector3 targetPt = target.position;
        targetPt.y += targetHeightOffset;

        Vector3 lookDir = targetPt - camPos;
        Quaternion rot = Quaternion.LookRotation(lookDir, Vector3.up);
        transform.rotation = rot;

        curPos = transform.position;
        transform.RotateAround(targetPt, Vector3.up, yaw);
    }
}

Its a 2d game :- )

You need to make sure that your camera moves after the player moves, but before the screen is drawn. The easiest way to do that is to put your camera code in LateUpdate.
In addition, if your character’s a Rigidbody or Rigidbody2D, you need to make sure it’s set to interpolate/extrapolate

5 Likes

Yes… : -)