0
\$\begingroup\$

i confused , when the object is at 0 rotation ( not rotated yet ) , it giving real value ( 0 ) , but when the object is rotated 180 degree , transform.rotation is giving false value ( 1 ) , this is the screenshot :

Faded - By Alan Walker , anyway have you play game like Demonophobia ? or Ib ? or Mad Father ?

If the picture is not clear enough , go here https://i.sstatic.net/miWIE.png .

Then this is my script that debugged the code and rotate the object :

void RotateFlip() {
    GameObject databasegameobject = GameObject.Find ("database");
    database databasechange = databasegameobject.GetComponent<database>();
    Debug.Log ("current object rotation is " + theiconarrow.transform.rotation.z + " degree ");
    if (databasechange.pengertianmenustate == 2) {
        if (theiconarrow.transform.rotation.z == 0 ) {
            theiconarrow.transform.Rotate (new Vector3 (theiconarrow.transform.rotation.x, theiconarrow.transform.rotation.y, 180), Space.World);
        }

    }

    if (databasechange.pengertianmenustate == 1) {
        if (theiconarrow.transform.rotation.z == 180) {
            theiconarrow.transform.Rotate (new Vector3 (theiconarrow.transform.rotation.x, theiconarrow.transform.rotation.y, 180), Space.World);
        }
    }
}   

I don't understand why this thing happened , is this a kind of bug or what ?

I am sorry if this already asked somewhere , but i just don't know how to find it at search engine ( neither here ) .

Extra question ( optional ) : is there any application to build app with easy coding and not an game engine ?

\$\endgroup\$
3
  • 1
    \$\begingroup\$ Unity stores rotations as quaternions (see the doc) with every component in the range -1.0 to 1.0 - see this question for more details \$\endgroup\$ Commented Jan 11, 2017 at 8:45
  • \$\begingroup\$ then what should i use to get the current rotation ? \$\endgroup\$ Commented Jan 11, 2017 at 8:47
  • 1
    \$\begingroup\$ As suggested in the answer you could use transform.eulerAngles instead. Or learn how to work with quaternions - both are valid options \$\endgroup\$ Commented Jan 11, 2017 at 8:49

1 Answer 1

1
\$\begingroup\$

Unity, like many 3D softwares uses Quaternions to deal with rotation (prevent the Gimbal Lock problem). You get a quaternion when you call theiconarrow.transform.rotation (a quaternion is represented by 4 values : x, y, z, w, but are not really the angles around the 3 axis with an additional value).

However, because quaternions are not easily readable by humans, the inspector shows you the euler angles (pitch, yaw, roll) of the rotation (which are the angles around the 3 unit axis). In your code, you can get the euler angles by calling : theiconarrow.transform.eulerAngles.

\$\endgroup\$
4
  • \$\begingroup\$ thanks ! :) the unity documentation are just too bad \$\endgroup\$ Commented Jan 11, 2017 at 8:50
  • \$\begingroup\$ i had another problem , the value of quarternions are increasing each rotated from 180 , back to zero then back to 180 again , like 1.E-50 then 2.E-525 , and just keep increasing , do you know why ? \$\endgroup\$ Commented Jan 11, 2017 at 8:56
  • 2
    \$\begingroup\$ I highly advise you to not deal with the direct values of the quaternions. Use the euler angles if you want to make comparisons, and the Quaternions static functions to manipulate a quaternion (rotate, ...) \$\endgroup\$
    – Hellium
    Commented Jan 11, 2017 at 8:58
  • \$\begingroup\$ well i guess i will just the power of variable instead those thing :P \$\endgroup\$ Commented Jan 11, 2017 at 8:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .