Gyro Rotation Offest Calculation or Alternate Solution?
So I have a script where I use the gyroscope data of an iPhone to turn a camera. As of right now, my script matches the camera's rotation with a Vector3 with altered axes, and for vertical and horizontal movements from the initialized position (phone is flat with screen pointing up), the script works fine, i.e. I turn the phone left and the camera turns left, I turn it right and the camera turns right. However, a problem i'm having is that if I turn the phone 90 degrees left/right, and then turn it 90 degrees up/down, the camera barrel rolls instead of moving up/down. If anyone knows the mathematical formula for fixing this issue, or just has a better solution, please let me know. Thanks.
http://forum.unity3d.com/threads/gyroscope-quaternion-to-unity-camera-help-please.75288/ Basically having the same problem as this guy,
Answer by Dave29483 · Jul 22, 2016 at 07:02 AM
You may find it easier if you have a parent object which handles panning and then apply tilt to the camera child object. Just make sure you zero out the other two unused rotation axes on each object.
e.g. parentRotation Vector3(0, pan, 0)
childRotation Vector3(tilt, 0, 0)
Yes, you would create an empty parent object :)
But this script makes it so that the camera will continually rotate if the phone is held at an angle right? I want the camera to match the angle of the phone, ie if the phone is pointing up, the camera points up.
Your answer
![](https://koobas.hobune.stream/wayback/20220612085236im_/https://answers.unity.com/themes/thub/images/avi.jpg)