Skip to main content
September 3, 2013

Control object by headtracking

Hey Guys,

still quite new to all this Unity-stuff.
I was wondering if it's possible somehow to control rotations of an object by headtracking without using the CharacterControler.
Are there any functions I could adress to read out the actual rotation of the Rift? Looked through the scripts and the forums a little, but wasn't succesful in finding so yet..
Also, is there a way to disable tracking of the different axises in the OVRCameraController?

Put simple, I'd like to have a fix Rift-Camera looking at an object which is rotated by moving the head..

Thanks in advance!
    This topic has been closed for replies.

    10 replies

    Up and Coming
    September 3, 2013
    Here is the script I am using for my flying game. You attach this to the rigidbody with the OVR prefab child, and boom, constant motion in the direction you are looking.

    var distance : float = 3;

    function Update() {
    transform.position = transform.position + Camera.main.transform.forward * distance;
    }

    I hope this helps.

    EDIT:
    The more I read your request, the more I realize that I didn't actually answer your question. Oh well... I'll leave this here anyway. Who knows if this will help somebody someday. :)
    Have you listened to the Rev VR Podcast yet? Listen and subscribe through iTunes or through Stitcher http://www.reverendkyle.com
    Inspiring
    September 3, 2013
    Probably a lot of ways to accomplish this, but here's the most straightforward way I can think of:

    If you're definitely not going to be using headtracking for the Rift camera in your project, you could go into OVRCamera.cs and comment out this stuff in SetCameraOrientation():

    		// * * *
    // Update camera rotation
    gameObject.camera.transform.rotation = q;

    // * * *
    // Update camera position (first add Offset to parent transform)
    gameObject.camera.transform.position =
    gameObject.camera.transform.parent.transform.position + NeckPosition;

    // Adjust neck by taking eye position and transforming through q
    gameObject.camera.transform.position += q * EyePosition;


    Then, to have your object rotate depending on the Rift's rotation, make a new C# Script called "UseRiftRotation", and paste the following in:

    using UnityEngine;
    using System.Collections;

    public class UseRiftRotation : MonoBehaviour
    {
    void Update ()
    {
    Quaternion riftRotation = Quaternion.identity;
    if(OVRDevice.GetPredictedOrientation(0, ref riftRotation))
    transform.rotation = riftRotation;
    }
    }


    And then drag this script onto the object you want to rotate with headtracking.
    Titans of Space PLUS for Quest is now available on DrashVR.com
    Up and Coming
    September 3, 2013
    Look up what the stuff in OVRDevice, and anything else that starts with OVR and there is probably a way. You can get the offset needed for the left and right eye through OVRDevice, so I don't doubt there is a way to get actual orientation. (I'd look, but I'm at work)
    Current Project: Virtual Reality Glove project
    September 4, 2013
    Thanx alot, especially @Drash, think that leads me into the right direction. I'll try that tomorrow and report if it worked for me.
    September 4, 2013
    Your solution was absolutely what I was looking for, thank you Drash!
    Inspiring
    September 4, 2013
    Glad to hear it!
    Titans of Space PLUS for Quest is now available on DrashVR.com
    New Participant
    September 5, 2013
    Dschonny --

    What application do you have in mind for this? I am interested in using the Oculus Rift for packaging design and visualization. I like the idea of having a 3D package "floating" in space in front of the user, and somehow manipulating it either with keyboard/mouse, or ideally with the motion tracking in the rift.

    Curious about your use case!
    Participant
    October 3, 2013
    "drash" wrote:
    Probably a lot of ways to accomplish this, but here's the most straightforward way I can think of:

    If you're definitely not going to be using headtracking for the Rift camera in your project, you could go into OVRCamera.cs and comment out this stuff in SetCameraOrientation():

    		// * * *
    // Update camera rotation
    gameObject.camera.transform.rotation = q;

    // * * *
    // Update camera position (first add Offset to parent transform)
    gameObject.camera.transform.position =
    gameObject.camera.transform.parent.transform.position + NeckPosition;

    // Adjust neck by taking eye position and transforming through q
    gameObject.camera.transform.position += q * EyePosition;


    Then, to have your object rotate depending on the Rift's rotation, make a new C# Script called "UseRiftRotation", and paste the following in:

    using UnityEngine;
    using System.Collections;

    public class UseRiftRotation : MonoBehaviour
    {
    void Update ()
    {
    Quaternion riftRotation = Quaternion.identity;
    if(OVRDevice.GetPredictedOrientation(0, ref riftRotation))
    transform.rotation = riftRotation;
    }
    }


    And then drag this script onto the object you want to rotate with headtracking.


    It's amazing what a simple google search can achieve. I am looking to do something fairly similar to what OP is describing. I want to be able to have a stationary camera and use the headtracking to move an object vertically. The end result will hopefully be that I can make a simple pong game using only the pitch from the headtracking to control the paddle.

    If anybody has any hints or tips about this please let me know. I'm very new to Unity + Rift development (well, development full stop).
    Up and Coming
    October 4, 2013
    You only want to move across the y axis?
    Participant
    October 4, 2013
    "boone188" wrote:
    You only want to move across the y axis?


    Yes. I only want the pong paddles to move up and down, for now.