- Home /
Quaternions rotating left and right, not forward and back
Hello.
I have a model. Imported said model to Unity. When instantiated, it is sideways, so I used the following code to rotate it:
_crescentInstance.transform.rotation = new Quaternion(0, 180, 0, 0);
After hitting play and realizing how dumb it was to rotate something in the other direction, i changed its' rotation to 90. Nothing happened.
Then I changed the rotation to 270. Nothing happened.
For some reason it's only accepting rotations along the Y-axis of 180 and 0. Anything other than that does literally nothing.
I've re-imported the model, and I'm positive the base rotation for the game object is 0. I've even tried setting the instantiated angle to the Quaternion, and I have the same results.
Moreover i've tried the Rotate() function as well, and that too yields the same results.It's as if my model has no Y axis of 270 or 90.
Is this why in the documentation it said not to modify the X Y Z and W values unless you know exactly what you're doing?
You could read this article :http://unitygems.com/quaternions-rotations-part-1-c/
Thanks for that link!
Now I have it... somewhat working.. but its still kind of bleh.
What I have now is kind of a random effect...
`Vector3 rotateAngle = new Vector3(Camera.mainCamera.transform.forward.x, Camera.mainCamera.transform.forward.y * 90, Camera.mainCamera.transform.forward.z); _crescentInstance.transform.rotation = Quaternion.LookRotation(rotateAngle);`
By random effect, I literally mean that it works 25% of the time. Regardless of my direction in game, it will fire exactly how it's supposed to 25% of the time. The other times it will be facing towards me, to the left, to the right, and on a side.
I've noticed that it varies greater in direction depending on where I'm facing, but it still generally goes towards one direction
Stop struggling to make things more complicated that they are. Just do this: yourInstance.tranform.Rotate(Vector3.right * 90)
Answer by Saturnix · Dec 09, 2012 at 12:58 AM
Seems like you don't really understand what a Quaternion is (don't worry! I don't know it too! LOL).
To rotate an object you should use Transform.rotate or Quaternion.Lerp. I would recommend reading this page: http://docs.unity3d.com/Documentation/ScriptReference/Transform.Rotate.html
That just about answered it, thanks!
I've known about most of the other "math" concepts although Quaternions are brand new to me... As put in the other link that was sent, I don't doubt you'd have to be on a Stephen Hawking level to understand it completely. Oh well :(