- Home /
Gyroscope rotation offset
Hi! I'm making a game using the gyroscope (2d game). When I rotate my phone, it rotates the player's character. However, when my phone is totally straight (landscape), my character isn't straight. (see screenshot) I tried to see and there's like an offset of 70° (when my phone is at 90°, my character is at 160°)
Here is my script:
void Update()
{
transform.rotation = GyroToUnity(Input.gyro.attitude)
}
Quaternion GyroToUnity(Quaternion q)
{
return new Quaternion(0f, 0f, -q.z, -q.w);
}
If I return a new Quaternion, it's just because I only want the Z rotation (because it's a 2d game).
I tried to do a simple addition like -q.z - 70 but then it does something weird and only moves between 179° and 180°. If anyone has the answer ^^
Thanks in advance!
Answer by Saikou_Gabu · Dec 30, 2021 at 12:44 PM
Hey again ! I found a solution to my problem. You can just put the object you want to rotate (in my case, the player) in another gameobject that is like rotated of 90° (if you want to rotate of 90°), and then rotate your object using the localRotation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613051054im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
3D camera relatively using gyro a la N.O.V.A. 2 0 Answers
gyro attitude different w.r.t to app open 1 Answer
How to obtain roll / tilt angle from gyroscope? 3 Answers
How to implement a mounted but movable headlight using the gyroscope? 1 Answer
quaternion - rotate camera based on original facing at scene start? 0 Answers