I am working on a project where I want to create a 'scrolling' effect using the gyroscope on mobile devices. The basic idea is that I have an Image
object in my scene and I want to be able to show different parts of it based on device rotation with the gyroscope. For example, you see the wall of a room, and by rotating your phone you can turn to see different parts of the room (but in 2D).
For now I managed to move my Image
using Input.gyro.attitude.eulerAngles.x;
from Gyroscope
like this:
protected void Update()
{
var x = transform.localPosition.x;
var gyroX = Input.gyro.attitude.eulerAngles.x;
x += -gyroX * Speed;
BackgroundImage.transform.localPosition =
new Vector3(x, transform.localPosition.y, transform.localPosition.z);
}
The problem I am seeing is that when Input.gyro.attitude.eulerAngles.x
reaches 86.0
it starts decreasing. Even if you are rotating your phone to the right, it changes its direction.
I checked the documentation, examples over internet, but didn't find anything about that.
The only rotation axis which I am interested in is X, because the app will be in portrait mode and I want to be able to move the image only horizontally (by x).
So the phone's rotation has to be similar to what a user would do while taking a panoramic photo:
If you have any idea what can cause that issue and how can I fix it, or any other suggestions for how can I achieve the thing I want to create, please share your knowledge.