- Home /
Get object rotation angle.
How can I get object's rotation angle. If I use transform.rotation it gives not the angle.
I know you have to use quaternion, but I am not sure how to do this. Please tell me.
Thanks.
Answer by _MGB_ · Feb 23, 2011 at 05:58 PM
Does Transform.eulerAngles give what you need?
if the object flips (and it will) then it displays a wrong value..
If you know this will happen you can compensate for it in your script. You pretty much end up doing that a lot with eulerAngles.
Ya know, the problem with giving people links to an answer rather that just repeat it or copy/paste the answer, is that when people like me are looking for an answer years from when you posted your reply....the link is long dead. useful pages removed while total waste of time pages - like this one- remain
That wasn't a link to an "answer" but simply a link to the documentation. This question and answer is over 8 years old. Things always can change over time. You have a copy of the documenation along with your Unity installation so you can look it up locally in the documentation.
Anyways I've updated the documenation link. Btw: copy and pasting an answer is actually the wrong thing. We actually close duplicate questions.
right, if I had the documentation I wouldn't be looking online. I started on v.3.4 or something and that was awhile ago. I have upgraded as far as I can without breaking the crap out of my game ( 4.9,..... 5 anything breaks it to pieces) and I do not see any documentation on my computer anywhere. I know the answer is old but answers are answers and the right ones are ageless. Just saying it is frustrating to google answers and 7 out of ten take you to dead links. If the page sending me there has no value then why not just delete it? perhaps doesn't really take up that much server space but neither did the links I was being sent to.
but thanks for the updating of the documentation but still stuck. Tried various things. I simply want to know if the plane in my flight sim is angled up or down. That value seems to change from pos to neg depending on which direction I am fling along Z. I did come across that info you updated in the link. Pretty cool but the values still wouldn't give me what I hoped for. positiveX if I climb, NegativeX if I dive. Using the mouse to do this I am able to get the value from the mouse movement accurately , but it always returns to zero ( the mouse value) so it doesn't say I climb or dive for very long. Probably doing something wrong . $$anonymous$$aybe Time.deltaTime? Doesn't really matter because I was unable to successfully change the sound pitch for the climb ( only the dive) and, again , it wouldn't last long. On a fools mission
Answer by muhammadtahiriqbal · Aug 28, 2015 at 12:25 PM
float Angle=Quaternion.Angle(Quaternion.Euler(new Vector3(0,0,0)),transform.rotation); this give the angle b/w two rotations
Your answer
Follow this Question
Related Questions
Is there no way to get reliable angles from a rigidbody? 2 Answers
Quaternion Rotation On Specific Axis Issue 0 Answers
Extrapolating Quaternion Rotation 2 Answers
Make Quaternion affected by float 1 Answer