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?
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!