How to get Oculus angle/rotation?

Hello, I was wondering what the method would be to check/detect the viewing angle or rotation of the Oculus VR headset. Is it as simple as grabbing it from the camera object’s transform properties, or is a different method required?

Or do I use this? http://docs.unity3d.com/ScriptReference/VR.InputTracking.GetLocalRotation.html

I will try both. Cam angle was changing, but in a way I didn’t expect (rotating Oculus in any direction seemed to affect x, y, and z of euler)

Tried this, with no compilation errors but also nothing showing in the console at runtime:

void Update () {
        angles = InputTracking.GetLocalRotation (VRNode.CenterEye);
        print ("X: " + angles.eulerAngles.x + "  Y: " + angles.eulerAngles.y + "  Z: " + angles.eulerAngles.z);
    }

(I also tried VRNode.head, but not sure if that is for head-tracking, which I am currently not using)

When I did the above code but used transform.eulerAngles.x etc. on the Camera (to which I have attached this script), it does output angles to console…

I had actually posted about this a couple days ago, you can find that here http://forum.unity3d.com/threads/unityvr-execution-order-and-transform.339415/

my workaround was to use a coroutine and wait until EndOfFrame() before grabbing the rotation, if I have time I’ll check out your InputTracking work around

@guru20 , I had a moment to look into this again and wrote a quick script I’d like to you try out, and a couple questions for you to answer, they’re going to sound stupid but I’m being sincere.

  1. Are you using UnityVR? If you’re using the Oculus SDK instead of the UnityVR then InputTracking probably won’t work.
  2. Assuming you are using UnityVR and it’s enabled, when you move your Rift around, does it move the Camera in the scene? (I had my Rift off at first, so my euler angles were all zero)
  3. Have you been running Unity for a long time? This issue seems to come and go randomly, sometimes just restarting fixes it - as scary as that is.
using UnityEngine;
using UnityEngine.VR;
using System.Collections;

public class InputTrackerChecker : MonoBehaviour {
    private    const string    logPrefix   = "InputTrackerChecker: ";

    [SerializeField] VRNode m_VRNode    = VRNode.Head;

    private void Start () {
        StartCoroutine(EndOfFrameUpdate());
    }

    private void Update () {
        LogRotation("Update");
    }

    private void LateUpdate () {
        LogRotation("LateUpdate");
    }

    private IEnumerator EndOfFrameUpdate () {
        while(true) {
            yield return new WaitForEndOfFrame();
            LogRotation("EndOfFrame");
        }
    }

    private void LogRotation (string id) {
        var quaternion  = InputTracking.GetLocalRotation(m_VRNode);
        var euler       = quaternion.eulerAngles;
        Debug.Log(string.Format("{0} {1}, ({2}) Quaternion {3} Euler {4}", logPrefix, id, m_VRNode, quaternion.ToString("F2"), euler.ToString("F2")));
    }
}

you can put it anywhere since it just queries the InputTracker (not the camera).
I also added a VRNode value so you can check any node quickly, I defaulted it to the Head instead of the CenterEye.
Hopefully you’ll see logs like this:

InputTrackerChecker:  Update, (CenterEye) Quaternion (-0.03, 0.21, 0.00, 0.98) Euler (357.11, 24.32, 359.54)
InputTrackerChecker:  LateUpdate, (CenterEye) Quaternion (-0.03, 0.21, 0.00, 0.98) Euler (357.11, 24.32, 359.54)
InputTrackerChecker:  EndOfFrame, (CenterEye) Quaternion (-0.03, 0.21, 0.00, 0.98) Euler (357.11, 24.32, 359.54)

I have “using UnityEngine.VR” as an include

So yeah, conveniently I just decided to start a VR project right as Unity announced native VR support, so I decided to try that instead of getting up and running with the Oculus SDK

My camera works fine – better now with p3 (in order to manually manipulate the camera for animations and “cut-scenes”, I needed to place it inside of an empty container, and in p1 it would not rotate or orient properly, but it does in p3)

I am going to try doing my game manipulations based on the camera rotations for now since I can’t get the InputTracking to show (although I might give your code a try, as well), because the camera rotation does seem to correspond well – just not sure if it’s the most efficient method. [I want a force to be applied right or left according to tilt/lean of head left or right. This corresponds to Z movement on my camera, with a left tilt being 90 degrees and a right tilt being 270 degrees.]

Hi Guru
Have you find the answer to your question? Instead of trying seeing the values on console set public variables and you will be able to see those.

HI
I am using Oculus VR
PLease let me know how to get orientation and how to print in UNity
I want to use it like mouselook but instead of mouse look i want to use HMD Look for Walking direction

Looking for Kind help
Thank you