Adding torque around a local axis

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Zakru

Hey, I have a spaceship that needs to be able to move around the world. Currently the ship can accelerate in any direction, and rotate to face different directions, but the RigidBody obviously doesn’t like the rotation, as it stops whenever I rotate the ship, and when I stop rotating it continues moving at a slower velocity.

So, it seems like I have to apply torque to the RigidBody as to not interfere with its own physics. But there are only functions for applying torque around the global axes! How do I apply torque around the ship’s local axes?

If I get the docs right then you actually pass the vector3 of the axis around which you want to rotate (multiplied by the force presumably). So try using a local axis for that. I.e. transform.basis.y

wombatstampede | 2019-05-26 17:30

Oh! I immediately just assumed the torque was in global euler angles, for some reason, since the docs of add_torque don’t mention that torque is also the axis, and so I didn’t even bother to look at apply_torque_impulse. Thanks for pointing that out.

Zakru | 2019-05-27 09:13