camera follows player shakes

i have this very basic script that i use to follow the player around but it shakes alot when it is in use i dont know if it is something to do with unity or the script is there anyway i can improve my code or is there any better codes. the code is:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class camerafollow : MonoBehaviour
{
    public Transform target;
    public Vector3 offset;
    void Update()
    {
        transform.position = target.position + offset;
    }
}

Try changing from Update() to LateUpdate().

Reason is that if you update player position in Update() you are guaranteed to get the most up-to-date player position if you set the camera’s position in LateUpdate(). Alternative would be script execution order but I’d avoid that as much as possible,

2 Likes