Unity gyroscope in 2D
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!
Answer by ddlgomes · Jul 12, 2018 at 04:04 PM
Hello, Did you managed to find an answer for your problem? I am new to Unity and currently I am trying to create something very similar to what you described, although a panorama viewer for videos, using 2D gyroscope. Thanks in advance!
Your answer
![](https://koobas.hobune.stream/wayback/20220612140851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using gyroscope to control a camera? 1 Answer
How to make font look sharp and smooth 1 Answer
I use prefabs in prefabs and when I correct the root prefab of child prefabs, items don't correct. 0 Answers
All object move together when try to drag one object only 0 Answers
Mobile 2d resolution scale 0 Answers