Search Unity

rotation from editor different from script ?

Discussion in 'Scripting' started by patricia, Sep 30, 2007.

  1. patricia

    patricia

    Joined:
    Aug 10, 2007
    Posts:
    73
    I'm having a problem,

    basically i notice that the values i see in the editor are not the same as the one in the script.

    myobject.transform.rotation.x is different from what i see in the editor.

    Why is that ? and how to get the correct values ? ( even if i force the rotation of my object by script i don't get the same position for my object ! )

    pin.transform.rotation.x = 0 lays it flat on the ground by script. but rotation.x = 0 stands up in the editor.
    I'm so confused :s

    the bottom text in the screenshot is Debug.log ( quille.transform.rotation.x + " - " pin.transform.rotation.y )

    as you can see, the editor rotations are different.

    helppppp ! :)
    Patricia.[/img]
     

    Attached Files:

  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    It doesn't say the rotation of the object in the editor, but it says it's euler angles, I think. It would be something like:

    Code (csharp):
    1. myobject.transform.localEulerAngles.x
     
  3. aaronsullivan

    aaronsullivan

    Joined:
    Nov 10, 2005
    Posts:
    986
    Right. The euler angles are in the editor.
    rotation is a Quaternion. If you aren't familiar, you can look them up in the script docs. Basically, the x,y,z component of the Quaternion are totally different than the euler angles most people are used to in 3D editors. There is never a simple direct correlation between the two either. :D
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    If you change the inspector to debug mode it will show the quaternion components of the rotation.
     
  5. tonytopper

    tonytopper

    Joined:
    Jun 25, 2018
    Posts:
    226
    One other thing to consider, for those that end up here from search results as I did, is that the Unity editor seems to rotate on the center point of the renderer.

    I was struggling with a similar problem and this worked:

    Code (CSharp):
    1. if (gameObject.TryGetComponent(out Renderer renderer))
    2. {
    3.     gameObject.transform.RotateAround(renderer.bounds.center, Vector3.forward, 45f);
    4. }