I'm using the function Rigidbody.MoveRotation in my script to rotate a cube. In the inspector, the rotation appears to go from 180° to -180°.
I want to write a simple script to find out how fast the cube is rotating. At first I wrote a simple:
Mathf.Abs(current_angle - previous_angle)
where the previous angles is the rotation angle from the previous fixedupdate. This does not always work though, since when the previous_angle is, say 170, and a rotation of 20 degrees happens, the current_angle becomes -170.
Is there a simple way to fix this? Right now I'm using an IF to check whether or not the two angles are near 180°, and I'm using a custom calculation for that case, but if the rotation speed is high, this could not work either.
Answer by FortisVenaliter
Apr 13 at 07:36 PM
Well, if you're already using MoveRotation, then the values you put in will be the rotation coming out, so you should already know it, right?
If the Rigidbody is rotating on it's own, it exposes an angularVelocity field that will tell you exactly how fast it's rotating on each axis, so you can look it up there without calculating it yourself.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
4 People are following this question.
Flip over an object (smooth transition)
Problem using Quaternion.AngleAxis around transform.up
Player Rotation Snapping
Problem with wave like movement when rotating around X and Y axis with mouse input // Please Close/Delete
Clamping Child's Rotation Relative To Partent's