- Home /
unexpected axis values when a sphere rotates 360 degrees around a game object
I'm experiencing some weird behavior that I cannot explain. Im using an empty game object as a central point ("origin") where a second game object (a sphere) revolves around it, completely. This is meant to mimic the rotation of the sun, in a full day-night cycle.
Firstly, I would have expected that the rotational (transform.eulerAngles.y) value would change along the y-axis as this game object moves/rotates around the origin. Instead, it is the (transform.eulerAngles.x) that is changing. I can't explain why?
Secondly, more importantly, I would have expected the transform.eulerAngles.x to return the degrees of 0-359. Instead, once the sphere hits 90 degrees, the transform.eulerAngles.y and transform.eulerAngles.z values flip from being "0" - to each being "180"... and the transform.eulerAngles.x decrements itself from 90 back to 0 again (where it really should have been 180 degrees).
I expected the sphere to increment beyond 90 degrees, and did not expect the other axis values to flip to 180 each.
I know I'm doing something completely wrong here. But I cannot figure out what? Does anyone have any suggestions? Answers?
Your description makes no sense. There is a good change you are having a stroke at this very moment (an hour ago). Call an ambulance.
Or post some code or something. Honestly, I have no clue what you're blathering about.
Answer by Owen-Reynolds · May 11, 2011 at 08:55 PM
Some code would help -- are you using transform.Rotate(1,0,0);
if so, then, yes, you are rotating around x.
The flipping numbers are probably classic gimbal lockish stuff. Some directions have multiple ways of rotating to get them. For example, a 180 degree y-spin is the same as a 180 z followed by a 180 on x. If you look, Rotate does the rotations in Local z, then x then y. So, if you get turned on your side, then a y rotation really is an x rotate (in world, non-local, space.)
Quaternions were invented (really, stolen) to solve this, but they are tricky to learn.
If the spin works, just ignore the numbers. It's a little like how Unity snaps -10 degrees to 350 degrees. If it's causing problems, try directly setting angles. Create Vector3 Angles;
and set Angles.x, Angles.y, Angles.z yourself (add 1 degree, or something) and set with with transform.eulerAngles = Angles;
. That will prevent Unity from snapping them around (it still will, but not on your copy.)
You are correct Owen. The piece of code responsible for the movement and rotation is as follows:
Sphere[0].transform.RotateAround(AroundThis[0].position, Vector3.right, (Time.deltaTime * _multiplier));
So, as I understand now, the rotation occurs on the x-axis.
Common mistake...seems like "right" says to rotate right, but really means to rotate around an L/R stick. $$anonymous$$ost plp would use Rotate for an x,y or z spin. RotateAround is primarily special cases: you have some odd axis of spin or don't want to rotate on your own (0,0,0)
Your answer
