Forum Discussion

🚨 This forum is archived and read-only. To submit a forum post, please visit our new Developer Forum. 🚨
Dschonny's avatar
Dschonny
Honored Guest
12 years ago

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!

10 Replies

Replies have been turned off for this discussion
  • 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. :)
  • drash's avatar
    drash
    Heroic Explorer
    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.
  • 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)
  • Thanx alot, especially @Drash, think that leads me into the right direction. I'll try that tomorrow and report if it worked for me.
  • Your solution was absolutely what I was looking for, thank you Drash!
  • 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!
  • djayne's avatar
    djayne
    Honored Guest
    "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).
  • djayne's avatar
    djayne
    Honored Guest
    "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.