- Home /
Rotation promlems past 90 and 270
Problem with rotation and I can't seem to fix it. Here is what I am using:
function Update() { transform.rotation.x += 20* Time.deltaTime; }or
function Update() { transform.RotateAround (transform.position, Vector3.right, 20 * Time.deltaTime); }What happens with the first one is it gets to a point and stops moving. The numbers on rotation x seem to stick around 0-1 without actually stopping. The rotate around script animated the object correctly, but the rotation of x goes up from 270 to 90, then counts back down to 270 after flipping the Y and Z rotation from 0 to 180. If I rotate manually in play mode and switch to the scene view to rotate using tools, it does the same thing. If I am trying to use something to match the rotation, it's fine for half the rotation on the x axis, but once it gets past the 90 and starts counting back down it messes it all up. any idea why it does this?
Answer by Eric5h5 · Oct 06, 2012 at 05:50 AM
Transform.rotation is a 4D quaternion, and rotation.x does not correspond to the x axis. Use Transform.Rotate instead. There is more than one valid way to represent a quaternion as euler angles (e.g. 0,0,0 is identical to 180,180,180), so reading one axis by itself is somewhat meaningless.
That just seems overly complicated. I am used to 3D Game Studio and there are several advantages to it than Unity, but Unity is better for cross platform and the AAA stuff being built in. Being able to use a .sav file for instance is one such advantage, I tried your solution, and it kinda works, but still having some issues.
transform.Rotate(Vector3.up * Time.deltaTime *20, Space.World);This works great, the x and z axis stay put no problem and the y just goes from 0 - 360 and just keeps looping. Now:
transform.Rotate(Vector3.right * Time.deltaTime *20, Space.World);this is a problem. The same issue happens where the y and z flip 180 and the x bounces back and forth. I'm beginning to think I just need to ignore the x axis and rotate my prefab to use the Y as it's primary. (It's a 2d game with 2 of the axis locked anyway). Here's the main issue though. Why is this only an X axis problem? I made a cube in scene view and added nothing but the rotate script above and the problem should be easily reproducible. I may need to figure out the X at some point but I think using Y might work fine too.
As I said, there's more than one valid way for a quaternion to be represented as euler angles, so the individual axis numbers are kind of meaningless. It doesn't matter that the y and z flip 180. It has no effect on how Rotate works; it's just a side effect of conversion since quaternions are used internally. Nothing is wrong.
Answer by Dragonlance · Oct 06, 2012 at 03:19 PM
Tried to put it in an empty object an then rotate in local space:
transform.Rotate(Vector3.right * Time.deltaTime *20, Space.Self);
That should do it.
Nope, doesn't work for me. I already tried it with both Self and World. $$anonymous$$aybe it's just my install? Using 3.5.5f3 standard ed. and have not changed any of the default physics or anything else.
And you have put your model into an empty object? This piece of code on the $$anonymous$$odel?
It works for me.
no, the model is not in an empty object. The latest test I did was just create a cube in the engine and attache the script directly.
Answer by Chouat.mohamed · Apr 14, 2015 at 05:27 PM
Hello , try to fixe your zone of work , 0 to 90 0 to 180 or 0 to 360
and se ur variable like this
alpha =((transform.eulerAngles.x%360)%180)%90;
So here the % have a role to find the angle betwen 0 and 90 180 360 .....
2kpi in math
Your answer
Follow this Question
Related Questions
Problems caused by non-unique Euler angle solutions 1 Answer
Rotate Around Planet with Spaceship Face Set on Path 1 Answer
Error with transform.RotateAround when I use a variable for the last parameter... 1 Answer
Object wont rotate in the opposite direction 1 Answer
How do you smoothly transition/Lerp into a new rotation? 3 Answers