- Home /
C# - Rotation around object axis
Hello, i need a script to detect objects rotation in respect to its own axis, not the worlds axis.
In more detail - i'm creating flight control system for my spaceship. I need my script to detect it's rotational motion, and as soon as that happens, make it fire thrusters to counter that rotational motion.
My script:
if (Spaceship.rigidbody.angularVelocity.z > 0){ rigidbody.AddForce (-transform.up * 500); }
My problem:
If Spaceship faces another diection of z axis, the script gives a "reversed" result. Instead of stopping the rotation, the thruster accelerates it.
Answer by Fattie · Mar 19, 2014 at 01:23 PM
generally you add Torque, not Force, to make something spin.
check out the doco...
AddRelativeTorque Adds a torque to the rigidbody relative to the rigidbodie's own coordinate system.
AddTorque Adds a torque to the rigidbody.
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.html
In this example, i need force - not to make my spaceship spin on its own, but be spinned by the thruster ins$$anonymous$$d. AddForce part is ok.
The problem lies in that i need the script to detect the spin direction in respect to spaceship axis (left to right wing) and not the world axis.
Answer by DEADmetal · Mar 19, 2014 at 02:14 PM
Could you please incorporate that in my code example? I have no idea where that should go. And the answer to your question is probably - yes.
I need the script to detect the spin of a Spaceship object in respect to its own axis (left to right wing), and not the world axis.
Your answer
Follow this Question
Related Questions
Get angle around a specified axis. 1 Answer
Control object yaw by two axis 1 Answer
How can I rotate a vector direction around an arbitrary axis? 0 Answers
rotate axis of movement 0 Answers
Rotation gameobject 0 Answers