- Home /
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.
Thanks !
Answer by Sebas · Dec 29, 2010 at 05:37 PM
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.
Answer by Ejlersen · Dec 29, 2010 at 05:39 PM
You are probably looking for:
transform.eulerAngles
or
transform.rotation = Quaternion.Euler(x,y,z);
Thank you Ejlersen, the 2nd one was exactly what I was looking for.
Actually what you see in the Inspector is transform.localEulerAngles. transform.eulerAngles is the worldspace rotation while localEulerAngles is the relative rotation to it's parent object.