The problem is you're using currentX as a starting position each time the Lerp is called, but the starting position should remain the same. This is what it should be instead:
float startTime = Time.time;
float startX = 0f;
float currentX = startX;
while( (currentX != finalX) && (Mathf.Abs(finalX-currentX))>marginOfError)
{
float localTime = Time.time-Time.deltaTime - startTime;
float percentCovered = localTime/duration;
//currentX = Mathf.Lerp (currentX, finalX, percentCovered);
currentX = Mathf.Lerp (startX, finalX, percentCovered);
yield return null;
}
↧