Unity3d gyroscope for Z axis only

I'm trying to figure out how a gyroscope works on iOS and Android, and I've looked at this tutorial: http://blog.heyworks.com/how-to-write-gyroscope-controller-with-unity3d/

What I would like to know, since I need to modify the source code (there is a link to this page there) so that it only reads from the z-axis of the phone? I already played with it and created a new Quaternion object like this:

Quaternion newRotation = Quaternion.Euler(initialRotation.eulerAngles.x, initialRotation.eulerAngles.y, gyroRotation.eulerAngles.z);
transform.rotation = newRotation;

      

it seemed to work, but then I noticed that when I rotate the phone around the y-axis (let's say 20 degrees) and THEN start to tilt it in the x direction, it reacts as if it would rotate in z- ( only slower).

What I would like to do is this: I want the object to be placed in the middle of the screen with an initial rotation of 0. When the phone is rotated around the z-axis, I want the object to rotate against the rotation of the phone so that it looks like the object is holding it is rotating no matter as the phone rotates around z.

+3


source to share





All Articles