using UnityEngine;
using Cinemachine;
using DG.Tweening;

public class DollyCameraTapMover : MonoBehaviour
{
    public CinemachineDollyCart dollyCart;
    public float moveDelta = 0.0005f; // super small movement
    public float moveDuration = 0.1f;

    private Tween currentTween;

    void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && currentTween == null)
        {
            MoveCameraSmooth();
        }
    }

    void MoveCameraSmooth()
    {
        if (dollyCart == null) return;

        float target = dollyCart.m_Position + moveDelta;

        // Wrap if in normalized
        if (dollyCart.m_PositionUnits == CinemachinePathBase.PositionUnits.Normalized && target > 1f)
            target -= 1f;

        currentTween = DOTween.To(
            () => dollyCart.m_Position,
            x => dollyCart.m_Position = x,
            target,
            moveDuration
        ).SetEase(Ease.OutSine).OnComplete(() => currentTween = null);
    }
}