I wanted to use my coroutine to smoothly interpolate the position and rotation of multiple GameObjects with the script attached to them. When I start the coroutine, the smooth part works fine, but all of my Objects get moved to the same position, which was not what I intended. I want to understand why that is the case, and if there is a smart way to deal with it.
This is what my coroutine looks like:
IEnumerator interpolate_Plate(Transform targ) { float passedTime = 0; while (!transform.Equals(targ)) { passedTime += Time.deltaTime; transform.position = Vector3.Lerp(transform.position, targ.position, passedTime); transform.rotation = Quaternion.Lerp(transform.rotation, targ.rotation,passedTime); yield return null; } yield break; } I was thinking about creating a mastercoroutine with a list in it and then call the smoothing part. Is the problem just, that the Reference of targ always gets reset for all coroutinecalls on the stack?
As requested by you the function that calls the coroutine:
public void move_Plate(Transform newPosition) { StartCoroutine(interpolate_Plate(newPosition)); }