Way to Move/Rotate object through List of points that would work with changing timescale

Hi all,

I’ve been trying to think of a way to do this for too many hours now… I simply want a way to smoothly move an object through a list of positions (this I sort of have already) and for this to be affected when timescale and fixedDeltaTime are changed.

I currently have a simple coroutine which when activated by a keydown iterates through the list of positions and sets them appropriately:

for (int i = targetPos.Count - 1; i > -1; i--)
        {
            transform.position = targetPos*;*

transform.rotation = targetRot*;*
}
This obviously will not be affected by slowing down time. So I tried replacing it with lerping or movetowards’ing but that either didn’t work at all or gave some crazy non-results. My last attempt to do this looks like this (excuse my probably obvious missunderstanding of how coroutines work, but by now I’ve been trying all sorts of craziness):
…(inside coroutine)…
for (int i = targetPos.Count - 1; i > -1; i–)
{
StartCoroutine(MovePos(targetPos_, targetRot*));
}
…(nested coroutine)…
IEnumerator MovePos (Vector3 endP, Quaternion endR)
{*_

while (transform.position != endP || transform.rotation != endR)
{

transform.position = Vector3.MoveTowards(transform.position, endP, Time.deltaTime);
transform.rotation = Quaternion.RotateTowards(transform.rotation, endR, Time.deltaTime);

}

if(transform.position == endP && transform.rotation == endR)
{
yield break;
}
}
This looks exactly the same as the simple method when played.
Any ideas?

Hello,

in your Coroutine you are Lerping correctly, but everything in While loop happening in one frame. You need to wait for another frame in each iteration.

while (transform.position != endP || transform.rotation != endR)
         {
 
             transform.position = Vector3.MoveTowards(transform.position, endP, Time.deltaTime);
             transform.rotation = Quaternion.RotateTowards(transform.rotation, endR, Time.deltaTime);

           //WAIT FOR ANOTHER FRAME
            yield return null;
 
         }