Search Unity

Newbie here Trying to pull Oculus rotational values

Discussion in 'AR/VR (XR) Discussion' started by Daube, Mar 8, 2015.

  1. Daube

    Daube

    Joined:
    Sep 12, 2013
    Posts:
    1
    Hi Everyone,

    I currently have a DK1 and i'm trying to Output the oculus's Y rotation values to an outside application using either TextWriter or some other drive connect. but i'm having trouble grabbing the Y rotation values and i don't know where there update. my end goal it to send these values to a java script any help is appreciated thanks!
     
  2. OpticalOverride

    OpticalOverride

    Joined:
    Jan 13, 2013
    Posts:
    161
    The code for grabbing the y rotation of any object in Unity is simple: transform.eulerAngles.y

    Create a C# script, and attach it to the Rift's game object in your scene. Make sure the game object you're attaching the script to rotates with the Rift, I believe the "Center eye" (or whatever it's called, I don't have a project open right now) will give the proper y angle. To check which object is going to give a proper y angle, simply use the inspector while running the application in the editor to check for proper changes in the y value. Write the following code inside your script's class:

    public float riftYAngle;

    void Update()
    {
    riftYAngle = transform.eulerAngles.y;
    }

    Now, that script's public variable, riftYAngle, will contain the Rift's y rotation. Send it out any way you want (pipes, TCP, etc.). Hope this helps!