- Home /
Get object rotation for x axis in degrees (360)
there are several questions like this but none has the correct answer. I found:
transform.localEulerAngles.x
transform.eulerAngles.x
but they will just return the flipped value at 90 degrees or something..
what is the correct answer ?
a function would be useful, with input (axis:String, rotation:Vector3)
and output 360 degree angle..
so basically heres the input and output needed (I observed the values by just dragging the x rotation gizmo on a brand new gameobject):
getRealRotation("x", Vector3(60,0,0)) => 60
getRealRotation("x", Vector3(70,0,0)) => 70
getRealRotation("x", Vector3(80,0,0)) => 80
getRealRotation("x", Vector3(90,0,0)) => 90
getRealRotation("x", Vector3(80,-180,-180)) => 100
getRealRotation("x", Vector3(70,-180,-180)) => 110
I dont understand whats wrong with using transform.eulerAngles. thats exactly what that is for.
Answer by robertbu · Jun 24, 2014 at 03:00 PM
Transform.eulerAngles is derived from the Transform.rotation, a Quaternion. It is not stored independently. There are multiple euler angle representations for any given physical rotation, and the representation does not remain constant throughout all rotations. Assuming you are doing the rotation through manipulating the Transform, then the usual solutions is to maintain your own Vector3 and treat eulerAngles as write-only. That is, you execute whatever rotation code to the Vector3 first, then you assign that Vector3 to eulerAngles. That way your Vector3 will always be in a format that you control.
In situations where this cannot be done (like when using a Rigidbody and forces), you need to create a point of reference and calculate the angle yourself. This question creates a HUD display for a plane and calculates the pitch, roll, and skew.
http://answers.unity3d.com/questions/696271/how-create-modern-aircrafts-hud.html
what if I only want to rotate the thing in 1 dimension (x-axis).. its a sun/moon object with 2 lights in it.. and I need the rotation to rotate a 2d texture.. meanwhile (I posted this question 2 days ago but on that account it didnt get accepted) I used a workaround by using a int to increase time per frame.. it works but.. its ugly code There has to be a way to calculate the value with a function, i'm sure many people would use it.. (according to the many questions that I found about it)
Your answer
Follow this Question
Related Questions
Snap the rotation 0 Answers
How can I rotate an object with certain degrees? 2 Answers
Limit Object Angle 2 Answers
how can i get Y rotation of Transform in degree ?? 1 Answer
rotate object with degrees 1 Answer