How to get a position value of a tween at a given time t?

using UnityEngine;
using DG.Tweening;

public class TweenPositionExample : MonoBehaviour
{
    public GameObject targetObject;
    public float duration = 5f;
    public float checkTime = 2f;

    void Start()
    {
        // Create a tween to move the targetObject to a new position over the duration
        targetObject.transform.DOMove(new Vector3(10, 0, 0), duration);

        // Use DOVirtual.DelayedCall to get the position at checkTime
        DOVirtual.DelayedCall(checkTime, () =>
        {
            Vector3 positionAtTime = targetObject.transform.position;
            Debug.Log("Position at time " + checkTime + ": " + positionAtTime);
        });
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.