# Slow a rigidbody to a stop over a set distance?

This might be a stupid question, but I just can’t seem to figure it out. I have a Rigidbody2D moving downward. When the rigidbody reaches a certain y-position I would like it decelerate to a stop over a set distance. I want the rigidbody to stop over the same distance every time regardless of the initial velocity. Sorry I don’t have any code to provide, but I don’t even know where to start with this one. How can I do this? Thanks for the help!

You can just use the physics equation to calculate deceleration.
Edit: Changed the code so that if the position is not equal to the desired position and it skips the position it still works. For eg. if you want to decelerate at y= -1 and the body goes from -0.8 to -1.2 the code will still work.

``````private bool firstTime = true;
private Rigidbody rb = GetComponent<Rigidbody>();
``````

Write this code in fixed update

``````if(transform.position.y<=yPos)
{
if(firstTime)
{
firstTIme = false;
float deceleration = (((rb.velocity * rb.velocity) * -1)/distance)
rb.velocity=deceleration;
}
}
``````