# Compute distance passed by scroll list while slowing down

Hi, Im struggling to compute distance mentioned in the title few days and come for help or some advices atleast.

My scroll view is horizontal ScrollRect with GridLayoutGroup as container.
Formula I found to compute passed distance:
distance = initSpeed * time - 0.5 * decelerationRate * time * time
Formula for decelerationRate:
decelerationRate = (finalSpeed - initSpeed) / time

Next Im trying to check are this formulas return acceptable values by placing list at center, appying some velocity to it, slowing it to zero in some time and comparing actual passed distance with formula’s values. You can check my code for that measurements below:

``````        float secondsToScrol = 2;
float initSpeed = 1000;
GetComponent<ScrollRect>().normalizedPosition = new Vector2(0.5f, 0f);
yield return new WaitForFixedUpdate();
Debug.Log(\$"POSITION {container.transform.localPosition}");

float decelerationRat = initSpeed / secondsToScrol;
float distanceWhileSlowingDown4 = initSpeed * secondsToScrol - 0.5f * decelerationRat * secondsToScrol * secondsToScrol;

GetComponent<ScrollRect>().velocity = new Vector3(initSpeed, startPos.y, startPos.z);

float aniTime = 0;
while (aniTime < secondsToScrol)
{
GetComponent<ScrollRect>().velocity = new Vector3(Mathf.Lerp(initSpeed, 0, aniTime / secondsToScrol), startPos.y, startPos.z);
aniTime += Time.deltaTime;
yield return new WaitForSeconds(Time.deltaTime);
}
Debug.Log(\$"EXP {distanceWhileSlowingDown4} = {container.transform.localPosition}");
``````

After executing this code Im getting next logs:

POSITION (0.0, 0.0, 0.0)
EXP 1000 = (1412.2, 0.0, 0.0)

Which say that actual passed distance is 1412, while computed by my formulas and expected is 1000.
Am I made some mistakes or to compute distance passed by slowing down movement in unity you need to use some specific formulas, different from real world physic ones?

Looks like I resolved this problem by myself. I have measured time before loop, mentioned in the post, after loop, substracted smaller from bigger and got the actual loop time is 3 seconds, and not 2 seconds, showed by ‘aniTime’ variable. In other words, if each step of my loop sleeps for Time.deltaTime its not mean that loop run time is close to Time.deltaTime * stepsOfTheLoop.

So I have updated my loop to really run 2 seconds of realtime

``````         float aniTime = 0;
float timeD = Time.time;
while (aniTime < timeToSlowdown)
{
...
aniTime = Time.time - timeD;
yield return new WaitForSeconds(Time.deltaTime);
}
``````

And after that inertionally passed distance after scrol started to equal to the distance calculated by formulas, mentioned in the post