Created
June 16, 2016 06:20
-
-
Save peroon/33169b18ecaef2e172c4bb5766321ea9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class GyroScene : MonoBehaviour { | |
public Transform target; | |
private Quaternion initialRotation; | |
private Quaternion gyroInitialRotation; | |
private bool isInitialized = false; | |
void Start(){ | |
StartCoroutine (StartCoroutine ()); | |
} | |
IEnumerator StartCoroutine(){ | |
Input.gyro.enabled = true; | |
yield return new WaitForSeconds (1.0f); // Gyro enable needs some time | |
initialRotation = target.rotation; | |
gyroInitialRotation = Input.gyro.attitude; | |
isInitialized = true; | |
} | |
void Update () { | |
if (isInitialized) { | |
Debug.Log (gyroInitialRotation); | |
Quaternion offsetRotation = Quaternion.Inverse (gyroInitialRotation) * Input.gyro.attitude; | |
target.rotation = initialRotation * offsetRotation; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment