How to get rotation in xyz

I apologize in advance, this is one of those questions where the answer is embarrassingly simple, yet I can't find it. But alas, progress trumps pride...

I would like to get the current rotation of an object in xyz degrees, like you see in the editor, rather than the object returned by transform.rotation. How do I do this?

2 Likes

http://unity3d.com/support/documentation/ScriptReference/Quaternion-eulerAngles.html

2 Likes

As the above link shows, you just have to check transform.eulerAngles.x for x, transform.eulerAngles.y for y, and transform.eulerAngles.z for z.

5 Likes
transform.rotation.eulerAngles

returns a Vector3. Use it as you like.

...err, nevermind. I had no idea that eulerAngles was a property of Transform. Nice!

http://unity3d.com/support/documentation/ScriptReference/Transform-eulerAngles.html

1 Like

It was embarrassingly simple :)
Thanks everyone!

I would like to get the current rotation of an object and feed it into another script, or another part of the same script, in an assortment of "If " statements to control different outcomes depending on the rotation on the Y axis.
I'm struggling to find an answer but I'm not from a scripting background and struggling generally.
Thanks chaps.

[quote=“RHD”, post:6, topic: 396873]
I would like to get the current rotation of an object and feed it into another script, or another part of the same script, in an assortment of "If " statements to control different outcomes depending on the rotation on the Y axis.
I’m struggling to find an answer but I’m not from a scripting background and struggling generally.
Thanks chaps.
[/quote]
I think it’d be better if you’d create a seperate thread for ppl to help you with your problem.

^^
and not bump a 5 year old thread.

[quote=“JamesLeeNZ”, post:8, topic: 396873]
^^
and not bump a 5 year old thread.
[/quote]

Don’t infringe upon their religious right to be practicing necromancers :smile:

HOBBY LOBBY

[quote=“GargerathSunman”, post:3, topic: 396873]
As the above link shows, you just have to check transform.eulerAngles.x for x, transform.eulerAngles.y for y, and transform.eulerAngles.z for z.
[/quote]

Loved your answer. It was simple and brief, and solved the problem quickly. Thanks very much.

Anyone know how to do this in JavaScript. I will not get into the C#. Not going to use C#.

[quote=“RockingGameDeveloper”, post:11, topic: 396873]
Anyone know how to do this in JavaScript. I will not get into the C#. Not going to use C#.
[/quote]
eulerAngles should work just as well in JavaScript as in C#, but why for the love of sanity would you still be using JavaScript in Unity in 2019? I’m honestly curious, you’re the first person I’ve seen in years that’s still on Javascript. Are you maintaining a legacy project that was created in 2009?

If you’re wondering why I’m so curious, I long ago (back when this was still actively debated on the forums, which was YEARS ago) wrote a long list of reasons why C# is objectively better, and I’ve yet to see anyone in the last decade make a good case for the other side. If you have some niche reason for using it I really, honestly would like to know what it is. I’m fascinated.

Kill javascript NOW!

[quote=“Davide1104”, post:13, topic: 396873]
Kill javascript NOW!
[/quote]
I’m glad you’ve awoken from your 3 year long coma. Welcome back

https://blogs.unity3d.com/2017/08/11/unityscripts-long-ride-off-into-the-sunset/

[quote=“Joe-Censored”, post:14, topic: 396873]
I’m glad you’ve awoken from your 3 year long coma. Welcome back

https://blogs.unity3d.com/2017/08/11/unityscripts-long-ride-off-into-the-sunset/
[/quote]

ha ha ha NO!
internet has no time, the rules always apply
it doesn’t matter if you write them after 1, 3, 10 years

1 Like