Hoyhoy, I have been trying to get the accurate angle of an object.
My objects shows its angle, and it is just over 1, when its at least 70-80 degrees.
I can times it by 10 and its a bit more accurate, but for what I am doing, I need it to be pretty precise, as these numbers represent the players score.
(total Angle * total Time spent with >0 degrees of angle is the formula. Hence why I want it accurate as can be)
#Here’s what I am using to get angle.
var angleDisplay : float = 0;
function Update(){
angleDisplay = rigidbody.angularVelocity.magnitude ;
}
Is there a more accurate way?
Cheers, Tim.
2 Answers
2
Given the names that unity has given to angularVelocity I am pretty sure it´s not the way to get the angle. In fact I think magnitude is not the angle but the angular velocity. Notice also that you can´t represent the whole rotation of a body with a single angle, hence we need quaternions. You could try the next code, but I don´t now how acurate it can be:
Vector3 angles = Vector3.zero
void FixedUpdate(){
angles += rigidbody.angularVelocity*Time.fixedDeltaTime;
}
Your question is unclear. What angle are you looking for?
If your game is 2D where objects move around the x and y axes, then rigidbody.angularVelocity.z will tell you how fast that object is rotating around the z axis.
If you want to know the angle that the object is currently rotated at (not the speed it is rotating) then you probably want something more along the lines of transform.eulerAngles.z.
'angularVelocity' is not the angle. It is the speed that the object is spinning. Unlike most of the angles in Unity, this one is in Radians, not degrees. You can use Mathf.Rad2Deg to convert between the two, but I don't think 'angularVelocity' is what you are looking for.
– robertbuThanks for the help, I will try it out :)
– ODNSEV7N