2
\$\begingroup\$

Using the following to turn a spaceship in a C# FarseerPhysics simulation.

 var turnPower = _Inventory.EngineTurnPower * time;
 body.ApplyTorque(turnPower);

If the user keeps holding in the turn key the ship will go into a superspeed turn och chaos were it eventually is impossible to tell which direction it is facing.

What would be some good way of limiting the turn speed that the user can cause, without limiting the simulation itself.

\$\endgroup\$
1
  • \$\begingroup\$ One idea I have to accomplish this is to get the delta rotation, and if it is greater than the max allowed and the user is trying to turn in that direction then i simply don't. But maybe theres a better physics way of doing it? \$\endgroup\$
    – JensB
    Sep 17 '17 at 19:24
4
\$\begingroup\$

There's no friction in space so what is happening is actually the proper realistic behaviour: The ship spins faster and faster.

If you want to limit rotation speed you can use Body.AngularDamping to add friction or clamp Body.AngularVelocity or both.

Adding friction/damping will reduce acceleration gradually.

Clamping velocity will put a hard limit on the speed and effectively cut acceleration to zero instantly.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.