- Home /
How does one use quaternion.euler(x,y,z) to rotate on y axis?
I use code:
var rotation = Quaternion.Euler(yrotation, xrotation, 0); transform.rotation = rotation; // Rem this out to freeze
What I have is that the object rotates on its local x no matter what visual angle it points in. But the Y rotation is in world y axis. In other words the object rotates about an axis that is vertical or top to bottom axis no matter what the object angular position is. Now I know the variable of yrot and xrot seem switched. But these are simply the computed from the mouse x and y direction which translates into degrees rotation about the axis. All my code works fine except this y axis quirk. TIA.
I modified the Z axis of the Quaternion.Euler to 45 and 90 degrees. I also modified the Transform.rotation to Transform.LocalRotation. The rotation action is the same. The X axis angle will not change. There seems to be a default world axis connection that makes a Top to Bottom axis that cannot be changed in its angular setting. I made the Z 45 degrees and I get the Y shaped gimble that spins on an invisible vertical axis ins$$anonymous$$d of an axis I denote. I am having a blank moment as to what to edit to make the gameobject spin on all 3 axis. When ever the gameobject faces up the room spins. When I look up and turn side to side the view should show a side to side movement. Ins$$anonymous$$d the ceiling spins at the center like looking at a pin wheel. Now that I have found this anomaly I will Youtube it to show exactly what the situation is.
I posted this here to better explain the problem I am experiencing. $$anonymous$$y gameobject is set to YAW. But as the pitch causes the gameobject to point up the YAW becomes a ROLL. I want YAW not matter what the angle of the gameobject is in space.
Then you want to set the local rotation of the object's transform.
That by definition is always relative to the object's axis
The first video I showed uses localRotation. I am not sure what you mean by 'set the local rotation of the object's transform'. Thanks http://docs.unity3d.com/$$anonymous$$anual/class-Transform.html
So, what you are saying is that you actually want rotation about the world axis?
If so then use transform.Rotate(x,y,z, Space.World);
Those are your two choices and the only two that makes sense: Rotation about a local axis or Rotation about the world axis
Answer by giantkilleroverunity3d · Jun 07, 2014 at 05:27 PM
One must designate the Space.Self
transform.Rotate(yrotation, xrotation, 0, Space.Self);
This is the answer. Now I just have to add a variable spin rate process.
Answer by Mario185 · Jun 03, 2014 at 09:11 AM
Hi,
I think the problem is that you have switched X and Y in Quaternion.Euler()
var rotation = Quaternion.Euler(yrotation, xrotation, 0);
Take a look at http://docs.unity3d.com/ScriptReference/Quaternion.Euler.html The first param in Quaternion.Euler is X not Y
regards
Good try. That switch is correct. The parameter connotates a direction of axial change, i.e. $$anonymous$$oving the mouse side to side on the x plane represents the rotation around the y axiz as in what direction is one looking at the horizon. $$anonymous$$oving the mouse up and down or away and towards oneself on the Y plane designates the pitch angle which the viewer will look below the horizon or high above the horizon. In free space this means flipping over oneself when looking up too far. Here is a better example: turn to your right and the scene view the display goes from right to left. If you flip 180 degrees on the X axis the display now goes still goes from right to left but the view sees the content going in reverse even though the viewer direction has not changed. Got it? Now when the x axis rotation goes up to the 90 degree position the view now spins on the viewers z axis or in front. This is how the physics engine treats gimble lock when in fact and in real life when a person looks up and turns thier head side to side the world does not spin but merely passes left to right or right to left because the gimble is the back of the neck and not controlled by a balancing or axial control mechanism.
Your answer
Follow this Question
Related Questions
Lerp Rotation broken 1 Answer
Problem with Constraint Camera Rotation C# 3 Answers
really annoying rotation problem. 0 Answers
Jittering effect when moving character and camera 2 Answers
Rotate & Translate 1 Answer