Velocity not clamped correctly when using force

I can’t seem to clamp my velocity effectively when using rigidBody2D.AddForce. For example I do the following:

rigidBody2D.AddForce(dir * 1000);

Before clamping this is the velocity and position:

(181.9, 0.0), (35.0, -2.4)

I then do this:

rigidBody2D.velocity = Vector2.ClampMagnitude(rigidBody2D.velocity, .1f);

And the velocity and position are what I’d expect them to be.

(0.1, 0.0), (35.0, -2.4, 0.0)

But then next fixed update cycle, after applying the same force, these are the numbers:

(181.9, 0.0), (38.7, -2.4)

As you can see the x position increased by 3.7 where I would have expected it to increase by .1 which is what I clamped it to.

In this setup the more I increase my acceleration (1000 in this case) the faster I’m allowed to go, even though I’m basically explicitly setting the x velocity to 0.1.

The force is added to the velocity during the fixed-update (multiplied by 1/mass and the time-step), not immediately. If you want to modify the velocity immediately then you should add the force as an impulse (instant force).

If you look at the AddForce documentation you will see that you can set the force mode to impulse to do this.