using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;

public class CameraLagBehind : MonoBehaviour
{
    public float lagBehindStrength;
    public float lagDistance;
    public float maxLagDistance;
    Vector3 targetPosition;
    float timeSinceLastCapture;
    public Transform lagObject;
    public Vector3 cameraTargetOffset;
    private void Update()
    {
        Vector3 targetPosition = transform.parent.position + cameraTargetOffset;
        Vector3 targetVector = targetPosition - lagObject.position;
        if (targetVector.magnitude > lagDistance)
        { 
            lagObject.position = Vector3.Lerp(lagObject.position, targetPosition, lagBehindStrength * Time.deltaTime);
        }

        if (targetVector.magnitude > maxLagDistance)
        {
            lagObject.position = targetPosition;
        }

        transform.position = lagObject.position;
    }
}
