Accessing postion of an object x seconds ago in c #

Hi all,

I’m trying to find the cleanest way to access the position that an object was in X seconds ago.
Are there functions to do this easily or do I need to constantly write the position data into an array, etc…
If it’s the array solution I’m curious how the code for this would look like.

Thanks so much,
Saschka

I’ve gone with the array solution until I can find something better.
I tore a few methods out of one of my classes so there may be some small errors here. But you can get a gist of the algorithm I’m using.

    private List<Vector3> _positionBuffer;
    private float _timer = 0;
    private bool _positionBufferFull = false;
    private int _positionBufferStepSize = 0;
    [SerializeFields]
    private GameObject[] _objects;

private void Start()
{
_positionBuffer = new List<Vector3>();
}  

private void Update()
    {
        //fill the position buffer
        if(_timer < _time)
        {
            _positionBuffer.Add(transform.position);
            _timer += Time.deltaTime;
        }
        else
        {
            if(!_positionBufferFull)
            {
                _positionBufferFull = true;
                _positionBufferStepSize = _positionBuffer.Count / (_numCopies+1);
            }
            
            _positionBuffer.Add(transform.position);
            _positionBuffer.RemoveAt(0);
        }

    private void PositionObjectsBasedOnTime()
    {
        for (int i = 0; i < _trail.Count; i++)
        {
            int index = (i + 1) * _positionBufferStepSize;
            //Debug.Log(i + " % " + percent + " d " + distance);
            _objects[_trail.Count - i -1].transform.position =_positionBuffer[index];
        }
    }