Unity3d Gyroscope only for Z axis

1k Views Asked by At

I'm trying to figure out how Gyroscope works on iOS and Android and I went through this tutorial: http://blog.heyworks.com/how-to-write-gyroscope-controller-with-unity3d/

What I would like to know, is how do I need to modify the sourcecode (there's a downloadlink on that page), so that it reads only from the phone's z-axis? I have already played around 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, when I rotate the phone around it's y-axis (let's say 20 degrees) and THEN start to tilt it in x-direction, it reacts like it would be rotated in z-direction (just slower).

What I would like to do is the following: I want to have an object placed in the middle of the screen with an initial rotation of 0. When the phone gets rotated around it's z-axis, I want the object to rotate against the phone's rotation, so that it looks like the object keeps it's rotation regardless of how the phone is rotated around z.

0

There are 0 best solutions below