AddForce only of velocity is below certain point.

Hi All,

I have a small spaceship that you can steer around. If you press a direction, I use AddForce to give the ship momentum.
The problem is, that it keeps adding force if you keep the button pressed, resulting in a very fast flying ship.

Is there a good way to limit the force added after a certain time? I have tried to limit it by only adding force if the ship is under a certain rigidbody.velocity thresshold, but that does not work very wel.

Couldn’t you just clamp the rigidbody’s velocity yourself to the maximum allowable in Fixed Update?

Not sure what you mean. Can you give me an example?

I’m guessing he means something like:

rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, myMaxVelocity);

On a side note, what ForceMode are you using to power your rigidbody? They all do very different things.

Erik

Oh wow, I didn’t even know about ForceModes. That is exactly what I need for my projectiles. I was just using AddRelativeForce.

Thanks!