Hello. I have a problem to which you pros definitely know the solution.
I need my script to detect objects rotation in respect to its own axis and not the world axis.
My script:
if (x.rigidbody.angularVelocity.z > 0)
Result:
I get the wanted result if object is facing positive direction of z axis but if object is facing negative direction of z axis, i get the “reverse” result.
Thanks in advance.
Use transform.localRotation instead of rigidbody.angularVelocity. The second one is a velocity.
I’m not really sure what you’re trying to do but if it’s a matter of not wanting negative numbers you can use:
if (Mathf.Abs(x.rigidbody.angularVelocity.z) > 0)
transform.localRotation doesn’t seem to be what i need. I need velocity here or at least delta change in rotation.
Let me clarify a bit more.
My goal:
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.
More of my script:
if (Spaceship.rigidbody.angularVelocity.z > 0){
rigidbody.AddForce (-transform.up * 500);
}
My problem:
If ship faces another diection of z axis, the script gives a “reversed” result. Instead of stopping the rotation, the thruster accelerates it.