# Stuttering when using movetowards in a coroutine

I have the following problem with a WebGL project I'm working on:

I have an object which I want to zoom out and move to a specific position at the same time, for this, I've created a coroutine which is called on click. On my computer, everything works perfectly fine, but whenever I try this function on a not that high-end computer, this coroutine stutters a bit.

I've tried deactivating every single shader or sprite that this object is using in order to discard high graphic usage, but the problem persists even if the object is a blank circle.

This is the coroutine I'm using:

  IEnumerator restorePosition() {
float counter = 0;
while(counter < duration) {
counter += Time.deltaTime;

if (counter > duration) {
counter = duration;
}

float framesPerTime = Vector3.Distance(zoomedTransform.position, storedPosition) / (duration - counter) * Time.deltaTime;
zoomedTransform.position = Vector3.MoveTowards(zoomedTransform.position, storedPosition, framesPerTime);

float framesPerTimeZoom = Vector3.Distance(zoomedTransform.localScale, storedScale) / (duration - counter) * Time.deltaTime;
zoomedTransform.localScale = Vector3.MoveTowards(zoomedTransform.localScale, storedScale, framesPerTimeZoom);

//restore solar system to original position
float solarSystemFrames = Vector3.Distance(solarSystem.position, solarSystemStartPOS) / (duration - counter) * Time.deltaTime;
solarSystem.position = Vector3.MoveTowards(solarSystem.position, solarSystemStartPOS, solarSystemFrames);
yield return null;
}

//zoomedTransform.position = storedPosition;
zoomed = false;
zoomedTransform.localScale = storedScale;

foreach(SpriteRenderer s in spriteChildren) {
s.sortingLayerName = originalLayer;
}

foreach(OrbitController o in planets) {
o.restartAnimation();
}
inTransition = false;

//set moon layer  values back to original
if (moon != null) {
moon.gameObject.GetComponent<SpriteRenderer>().sortingLayerName = moonLayerName;
foreach (Transform child in moon) {
child.GetComponent<SpriteRenderer>().sortingLayerName = moonLayerName;
}
moon.GetComponent<MoonBehaviour>().zoomOut();
//reset null transform and layer names
moon = null;
moonLayerName = null;
}
yield break;
}


Could you give me an idea of what I'm doing wrong? , I've also tried Lerp and that didn't solve the problem. Thank you!

If you do not want the routine to be framerate dependent then you can use WaitForFixedUpdate() or put the movement in FixedUpdate() These have a fixed timestep loop