Skip to main content
Up and Coming
August 2, 2016
Solved

Unity and Rift | player position in relation to camera

  • August 2, 2016
  • 12 replies
  • 7490 views
Hi,

I'm planning to build a 1:1 model of the space I have the Rift setup in, which includes a table. I also want the headset to match the physical space positionally. Is there a way to adjust the player controller so that it lets the headset load in the proper space in relation to where the camera is setup? I think I'm looking for something more like a 'player controller' for the camera. So I can position the camera in the Unity scene to match the real one - and have the headset/player created in relation to that?
    This topic has been closed for replies.
    Best answer by vrdaveb
    Try something like this:

    using UnityEngine;
    using System.Collections;

    public class AlignToTracker: MonoBehaviour
    {
    public OVRPose trackerPose = OVRPose.identity;

    void Awake()
    {
    OVRCameraRig rig = GameObject.FindObjectOfType<OVRCameraRig>();

    if (rig != null)
    rig.UpdatedAnchors += OnUpdatedAnchors;
    }

    void OnUpdatedAnchors(OVRCameraRig rig)
    {
    if (!enabled)
    return;

    OVRPose pose = rig.trackerAnchor.ToOVRPose(true).Inverse();
    pose = trackerPose * pose;
    rig.trackingSpace.FromOVRPose(pose, true);
    }
    }

    12 replies

    bcoyleAuthor
    Up and Coming
    August 3, 2016
    Hey vrdaveb! This sounds promising - although so some of the info is going over my head. Is the sensor the rift camera? or the headset? This project is site specific so the camera will stay fixed for all vr demos.

    If there's anything you can whip up that would help solve this in Unity I'd be happy to play with it. Like I said before - I plan to 3d scan the workspace to help in alignment of game objects with the physical space.
    http://www.quitenice.co
    vrdavebAnswer
    Inspiring
    August 3, 2016
    Try something like this:

    using UnityEngine;
    using System.Collections;

    public class AlignToTracker: MonoBehaviour
    {
    public OVRPose trackerPose = OVRPose.identity;

    void Awake()
    {
    OVRCameraRig rig = GameObject.FindObjectOfType<OVRCameraRig>();

    if (rig != null)
    rig.UpdatedAnchors += OnUpdatedAnchors;
    }

    void OnUpdatedAnchors(OVRCameraRig rig)
    {
    if (!enabled)
    return;

    OVRPose pose = rig.trackerAnchor.ToOVRPose(true).Inverse();
    pose = trackerPose * pose;
    rig.trackingSpace.FromOVRPose(pose, true);
    }
    }