Hi,
I would like to ask a question about gyroscope in 2D games. (I know there is already answers about rotating camera using Gyro, but that’s not what I am trying to achieve).
I have a scene where I use an Image
as a background to my Canvas
. The idea is that I want to change the position of that background image depending on rotation of device (gyroscope). As it is a 2D scene I can’t rotate it, so that’s why I am moving the image by X. Here is what I am using for now:
var x = transform.localPosition.x;
var gyroX = Input.gyro.attitude.eulerAngles.x;
x += gyroX * 5;
BackgroundImage.transform.localPosition =
new Vector3(x, transform.localPosition.y, transform.localPosition.z);
This code is not working quiet well. The problem is that when I start to rotate device only by X
at some point,after Input.gyro.attitude.eulerAngles.x
reaches 87 degrees, it start to get smaller (86, 85 and etc.) which starts to move image not properly.
P.S. My basic idea is to create something like Panorama viewer (not 360) for 2D using Gyroscope.
Any advices, suggestions how can I achieve this?
Thanks in advance!