I’ve been bashing my head for a while on this. Here’s what I’ve managed to rule out:
-The CoRoutine is called only once.
-The while loop is constant, yet doesn’t crash.
-The “percentage” float jitters around 0.2F
Here’s the code:
IEnumerator MoveTo(Vector3 endPosition)
{
Vector3 startPosition = transform.position;
Vector3 currentPosition = startPosition;
float smoothTime = timer;
float vel = 0.0F;
float percentage = 0;
// yield return new WaitForSeconds(delay);
while (percentage < 1)
{
percentage = Mathf.SmoothDamp(0F, 1F, ref vel, smoothTime);
print (Time.time);
currentPosition = Vector3.Lerp (startPosition, endPosition, percentage);
transform.position = currentPosition;
yield return 0;
}
}