- Home /
Can't Rotate around just Y Axis
I have an empty object rotating inside of the ball, and rotating the ball itself. I am trying to rotate the empty object around it's Y axis to turn the ball. I have tried :
down.Rotate(Vector3.up*-10.36997);
down.Rotate(0,-10.36997,0);
down.rotation.y -= 10.36997; //this one just does unspeakable things to the entire rotation
down.RotateAround(down.position, down.up, -10.36997);
All of these should rotate around the Y axis, ONLY, right? Well, no, not so much. It rotates around the Y axis properly but it also affects the X and Z rotation, anyone know why?
sry i dont understand what you want to do. you have 2 objects inside of each other. are they parented? a ball... give us abit of background about the ball. you want the to rotate independantly, one one way and another the other way?
the sound like they are both game objects, if you can make one rotate, then you should be able to make a reference to the other and put down.rotate in front of the other object also. they are the same game entity, a game object.
Answer by aldonaletto · Sep 22, 2012 at 07:06 PM
If you're talking about the X and Z fields you can see in the Inspector/Rotation, don't mind: Unity shows localEulerAngles in the Rotation fields. This property doesn't actually exist as a variable - it's calculated on the fly based on transform.rotation. Since there are several XYZ combinations equivalent to a given rotation, Unity chooses one of them based on an internal and totally obscure policy. This may result in weird changes in these fields when certain points are crossed - but the weird values returned are valid and equivalent to the current rotation.
The first two instructions should do the job ok, the 3rd is a complete nonsense (rotation is a quaternion - don't mess with its components!) and the 4th is a complicated and time consuming way to do what you want.
Anyway, if you're experiencing problems like the Y local axis being tilted after some time, keep your own localEulerAngles, rotate them mathematically and update the object's localEulerAngles, like this:
private var euler0: Vector3;
function Start(){ euler0 = down.localEulerAngles; }
// to rotate the object: // rotate the angle mathematically in modulo 360: euler0.y = (euler0.y - 10.36997) % 360; down.localEulerAngles = euler0; // update the actual rotation
The rotation must be kept in modulo 360, or weird things may happen when out of range values are reached!