How is the rotation of a Transform converted into a Vector3 in the inspector ?

Every GameObject's Transform has position, rotation and scale values in the inspector. Rotations are represented by a Vector3 (3 values; x, y and z).

How is the Transform Rotation Quaternion converted into this Vector3 ?

I've tried doing Quaternion.LookRotation(aVector3) as well as setting the same values to a Quaternion (and leaving the w on zero) but none the tries gave me the same result as touching the values manually in the inspector.

In other words, lets suppose I have a Vector3 variable in my script and I want that modifing that have the same result as modifing the Transform's rotation.

Example image

Thanks !

Are you looking for transform.eulerAngles?

Using eulerAngles will set the exact same values as you can see in the inspector. Unity does the transformation between quaternion and eulerAngles automatically. For more information on this transformation, try Wikipedia or using Google will give you plenty of results.

You are probably looking for:



transform.rotation = Quaternion.Euler(x,y,z);