I have watched a few videos and tried to read up on the documentation then just doing some simple test and using: Debug.Log("Rotation X:" + transform.rotation.x); Debug.Log("Local Rot X:" + transform.localRotation.x); Debug.Log("EulerAngles X:" + transform.eulerAngles.x); Debug.Log("Local Euler X:" + transform.localEulerAngles.x); to try to figure it out. Here is what my issue is though. I have a cube I set its rotation to 0,0,0 and then click play and watch the debug obviously it reads 0 on everything. I then rotate it by the x axis and if everything was set to 0,0,0 then it outputs as I would expect. What I am trying to get though is to rotate the object on the z axis lets say by 90 degrees. Then I want to rotate it on the worlds x axis. But when I rotate with the x axis(using the rotate tool) it rotates it on the y axis. Surely I am just missing something but I have been banging my head on this trying to figure it out. I have a object that rotates in all directions but in my code I am just telling it ok if right/left arrow pressed rotate on z axis. If up/down is pressed rotate on x but like said above if im already rotated on z then I would really be wanting to rotate on the y axis if that makes any sense. Maybe there is a math equation I am not seeing that would help me? Thanks! Weylin
Use Quaternions. They don't go to 180 twice. It comes down to rotation order. I looked for a video to explain this but it disappeared. Seems you rotate 90 on the X, 90 on the Y and 90 on the Z and then reverse the order you do not get back to where you started. It has to do with rotation order. I believe X is last, Z is first and Y is second in Unity. I resorted to dropping objects into an empty game object and rotating that on the Z axis and orienting the mesh with its X axis aligned to the Z axis in order to get a simple vertical and horizontal compass working with an X axis input...which became a Z axis input to the parent. HTH BTH
Sorry for not responding I didnt get an email saying there was a response even though it showed im signed up on the thread. I will look at quaternions again and see if I can get any ideas on how to accomplish this. Its really driving me bonkers.
You might want to try Transform.Rotate which will turn it x degrees on whatever axis at any time. Make sure to use the scripting class list whatever you do (best reference): http://unity3d.com/support/documentation/ScriptReference/Transform.Rotate.html Remember also, that y is UP in Unity.
Thats what I ended up doing it was so simple I am not sure how I over looked it? I am thinking I was trying to make it much more complicated then it needed to be. Here is kinda what I did(its for a ship you fly around) Code (csharp): bool rotating = false; float v = 0; float h = 0; if (Input.GetAxis("Vertical") != 0) { v = verticalSpeed * Input.GetAxis("Vertical"); rotating = true; } if (Input.GetAxis("Horizontal") != 0) { h = horizontalSpeed * Input.GetAxis("Horizontal"); rotating = true; if (!invertLeftRight) h *= -1; } transform.Rotate(v,0, h); float translation = forwardSpeed * Time.deltaTime; transform.Translate(0,0,translation); Ignore the rotating variable. I use that to auto level the ship if they are not rotating on any of the axis.