- Home /
The question is answered, right answer was accepted
Displaying Z Rotation through script
So I have created a dandy Airplane script, while your flying it displays your Speed, Turning Speed, Rotating Speed, ect. But I also want to display the Z Rotation of the airplane to help players know where they are but have no idea how to. Ive tried looking it up but all it brings me to is how to rotate an object which isn't what I want. I know theres probably a very simple answer but how would I be able to find out the Z Rotation through script and display it? Here is a snippet out of my script to show what Im trying to show. (This Displays the speed the player is going up/down)
if (GUI.Button (Rect (20,40,160,20), "Y-Speed: " + YSpeed)) {
Answer by sethuraj · Oct 21, 2013 at 06:21 AM
Use 'transform.rotation.z' to get the z rotation value of any transform.
It may have "worked," but it is not a good solution. Transform.rotation is a Quaternion which is a 4D, non-intuitive construct. The values go from 0.0 to 1.0. You can use transfrom.eulerAngles, but note the are multiple euler angle representations for any physical rotation, so the angle you get back may not be the one you expect.