Search Unity

VR Gyroscope Windows Phone - Problem

Discussion in 'AR/VR (XR) Discussion' started by gerban, Jun 20, 2015.

  1. gerban

    gerban

    Joined:
    Jun 20, 2015
    Posts:
    1
    Hi,

    I have a problem with the script gyro camera.
    Roll axis is reversed as it means tilt the phone upwards it goes down.
    For a long time I try to solve the problem

    I can not solve the problem please help !
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class HeadTrack : MonoBehaviour
    5. {
    6.     private bool gyroBool;
    7.     private Gyroscope gyro;
    8.     private Quaternion rotFix;
    9.     private Vector3 initial = new Vector3( 90, 0, 0);
    10.      
    11.     // Use this for initialization
    12.     void Start()
    13.     {
    14.         Screen.orientation = ScreenOrientation.LandscapeLeft;
    15.         Screen.sleepTimeout = SleepTimeout.NeverSleep;
    16.  
    17.         gyroBool = SystemInfo.supportsGyroscope;
    18.  
    19.         Debug.Log("gyro bool = " + gyroBool.ToString());
    20.  
    21.         if (gyroBool)
    22.         {
    23.             gyro = Input.gyro;
    24.             gyro.enabled = true;
    25.  
    26.             rotFix = new Quaternion( 90, 0, 0.7071f, 0.7071f);
    27.         }
    28.         else
    29.         {
    30.             Debug.Log("No Gyro Support");
    31.         }
    32.     }
    33.  
    34.     // Update is called once per frame
    35.     void Update()
    36.     {
    37.         if (gyroBool)
    38.         {
    39.             var camRot = gyro.attitude * rotFix;
    40.             transform.eulerAngles = initial;
    41.             transform.localRotation *= camRot;
    42.         }
    43.     }
    44. }
     

    Attached Files:

    Last edited: Jun 20, 2015