How to reset or erase force that is pushing a rigidbody?

Hello

I use AddForce to push objects around.
and objects are gliding on the ground while force is pushing them. but how to “measure” strength of that force?

When object reach some point, I want it to stop moving. and cancel all the forces that are affecting that object.

Can you help me somehow?

To measure the current velocity of the rigidbody just use rigidbody.velocity. To stop the rigidbody, or cancel the forces, set rigidbody.velocity = Vector3.zero.

1 Like

you can freeze position and rotation if it reaches a certain point like so.

transform.rigidbody.constraints = RigidbodyConstraints.FreezeAll;

or you can check the value of velocity and make the object heavier by adding mass as long as the velocity of the rigidbody is not zero.
basically make the object heavier if its moving until it cannot be pushed anymore.

if(transform.rigidbody.velocity.magnitude != 0) {

	transform.rigidbody.mass++;
}

or if it reaches a certain mass then freeze it so it doesn’t move. there’s a lot of ways you can do this. :slight_smile:

hope that helps

This could be dangerous if you want to apply new forces to the rigidbody later, as it will be too “heavy”.

you can always have a reset function after freezing it . . .if you reach a certain mass then freeze it and reset the mass . . . :slight_smile:

Maybe something like this would be easier and could use a scriptable dampening rate?

if(transform.rigidbody.velocity.magnitude != 0) 
{
    Vector3 dampeningDirection = transform.rigidbody.velocity.normalized * -1.0f;
	transform.rigidbody.AddForce( dampeningDirection * dampeningRate);
}
1 Like

This ^ :slight_smile: it should work fine.