localEulerAngles.x rotates as in world space

Hi! I’m making a game with flying pigeon on android with accelerometer contol, and i have a trouble with rotating it in local space. Everything is allright when i’m flying straight and want to turn up or down (around X axis in local space).

When i want to turn left or right, firstly i need to lean to one side (rotate around z axis - blue arrow), and then to rotate around X axis in local space (red arrow).

But when i rotate around X axis in local space, it turns up, just as in world space! (red arrow, wanted rotation - green arrow)

Here is code i use to rotate it:

transform.localEulerAngles = new Vector3 (-Input.acceleration.z * rotationAngle,	
			                       transform.localEulerAngles.y,
			                      -Input.acceleration.x * rotationAngle);

It gives the same result as using transform.eulerAngles
and transform.localRotation gives the same result as transform.rotation

transform.Rotate with local space works properly, but it’s not suitable for accelerometer control.
What’s the problem?

Well, is your object actually a child of another object? If not ALL local properties are “local to the world” and do exactly the same as the world space properties. The Rotate method applies a relative rotation to your object. localEuerAngles (or localRotation) is an absolute rotation relative to the parent. Also euler angles have a fix order in which the rotations happens.

In Unity it’s: z, x, y. You also shouldn’t use eulerAngles for such a control as euler angles suffer from gimbal lock. It’s better to directly use Quaternions. I would probably use a combination of LookRotation and AngleAxis to specify the initial rotation and a rotation based on the gravity vector.