Search Unity

How to get rotation in xyz

Discussion in 'Scripting' started by cmh322, Aug 22, 2009.

  1. cmh322

    cmh322

    Joined:
    Apr 3, 2009
    Posts:
    70
    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?
     
    cryptex. and ei1 like this.
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  3. GargerathSunman

    GargerathSunman

    Joined:
    May 1, 2008
    Posts:
    1,571
    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.
     
    dman8723, Knarhoi, cryptex. and 2 others like this.
  4. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    usingunityengine likes this.
  5. cmh322

    cmh322

    Joined:
    Apr 3, 2009
    Posts:
    70
    It was embarrassingly simple :)
    Thanks everyone!
     
  6. RHD

    RHD

    Joined:
    Mar 30, 2009
    Posts:
    719
    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.
     
  7. Magiichan

    Magiichan

    Joined:
    Jan 5, 2014
    Posts:
    403
    I think it'd be better if you'd create a seperate thread for ppl to help you with your problem.
     
  8. JamesLeeNZ

    JamesLeeNZ

    Joined:
    Nov 15, 2011
    Posts:
    5,616
    ^^
    and not bump a 5 year old thread.
     
  9. Tomnnn

    Tomnnn

    Joined:
    May 23, 2013
    Posts:
    4,148
    Don't infringe upon their religious right to be practicing necromancers :D

    HOBBY LOBBY
     
  10. CrazyZombieKiller

    CrazyZombieKiller

    Joined:
    Jun 8, 2015
    Posts:
    6
    Loved your answer. It was simple and brief, and solved the problem quickly. Thanks very much.
     
  11. RockingGameDeveloper

    RockingGameDeveloper

    Joined:
    May 28, 2015
    Posts:
    18
    Anyone know how to do this in JavaScript. I will not get into the C#. Not going to use C#.
     
  12. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    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.
     
  13. Davide1104

    Davide1104

    Joined:
    Jun 12, 2013
    Posts:
    38
    Kill javascript NOW!
     
  14. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
  15. Davide1104

    Davide1104

    Joined:
    Jun 12, 2013
    Posts:
    38
    Joe-Censored likes this.