- Home /
Camera Rotation using Gyroscope: Yaw and Pitch reversed
Hi,
I found some code that uses Input.gyro.attitude to rotate the camera. It's working, however the Yaw and Pitch are reversed. The pitch is rotating left/right and the Yaw is up/down. Here is the code in the Update function.
Quaternion offsetRotation = Quaternion.Inverse(gyroInitialRotation) * Input.gyro.attitude;
cam.transform.localRotation = initialRotation * offsetRotation;
In the Start function I am setting the initial rotations.
initialRotation = transform.rotation;
gyroInitialRotation = Input.gyro.attitude;
I am on iOS. Can someone please let me know how I can flip the Yaw and Pitch. If possible, I would like to not allow roll.
Thanks Much
Answer by ina · Oct 05, 2012 at 01:43 AM
phoberman has a nice gyro script that may help. it works well on iOS, but has been off and on flipped by a quat, due to Unity being inconsistent and sloppy in their Android updates.
Answer by ulissescad · Jul 29, 2016 at 12:29 PM
I used some examples of reply and unity to made this code, and him works fine to me:
float yRotation; float xRotation; void Start{
Input.gyro.enabled = true; } void Update{ yRotation += -Input.gyro.rotationRateUnbiased.y; xRotation += -Input.gyro.rotationRateUnbiased.x;
transform.eulerAngles = new Vector3(xRotation, yRotation, 0); }
Your answer
Follow this Question
Related Questions
Why is the Gyroscope inverted? 0 Answers
Virtual Reality - Android Gyroscopic Camera - Pitch and Roll Issues. 1 Answer
3D camera relatively using gyro a la N.O.V.A. 2 0 Answers
Gyroscope Orbit Android 1 Answer
How to force camera rotation? 1 Answer