# Condition implementation Problem

Just take this example :

``````void Start ()
{
StartCoroutine("TriggerCubeAnimation");
}

IEnumerator TriggerCubeAnimation()
{
foreach (var o in cubes)
{
while (o.transform.position.y<fMaxLimit)
{
o.transform.Translate(v3speed.x * Time.deltaTime, v3speed.y * Time.deltaTime , v3speed.z * Time.deltaTime);
Debug.Log(v3speed.x*Time.deltaTime + "  " + v3speed.y*Time.deltaTime + "  " + v3speed.z*Time.deltaTime);
yield return null;
}
}
yield return new WaitForSeconds(1.0f);
}
``````

I have Four Cubes in Row what i want is when my first cube start animation and when it reached at position 3.0f at Y-axix then the other cube start its animation all four cubes reached at 3.0Y in a row . like first then second then third and then fourth. and it does. But problem start when i want to make it faster if i make v3speed.y a big value it over reached the while condition and give some thing weired values.

for example :
if fMaxLimit is 3.0f.
then if i make v3speed.y = 20.0f
the v3speed.y increses 20 per/sec and

If you give it large steps like that it will of course overshoot, you never tell it to stop at 3. for example an iteration calculates v3speed.y * Time.deltaTime which is let’s say 0.524f, and v3speed.y was already at 2.9f it will be 3.424. If you want to keep it from overshooting you can clamp it’s magnitude with Mathf.clamp, or calculate the next value without assigning it and check if it is larger than the fMaxLimit. If it’s larger then just make it equal fMaxLimit. Otherwise Translate it.