Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Possible to set Vive tracking universe to seated in 5.4?

Discussion in 'AR/VR (XR) Discussion' started by nickpettit, Sep 2, 2016.

  1. nickpettit

    nickpettit

    Joined:
    Dec 31, 2013
    Posts:
    33
    I'm creating a cross-platform seated VR game for Rift, Vive, and PlayStation VR.

    When I call InputTracking.Recenter() it works as expected on the Rift. However, on the Vive, it appears that the tracking universe is set to room-scale by default. This means that players have to sit in the middle of the room scale tracking volume, rather than sitting in a fixed spot.

    When using the SteamVR plugin, it's possible to set the tracking universe to seated, either through the SteamVR prefab or through script, like this:

    Code (csharp):
    1. Valve.VR.OpenVR.Compositor.SetTrackingSpace(Valve.VR.ETrackingUniverseOrigin.TrackingUniverseSeated);
    Can the same thing be done using the Unity integration with the OpenVR SDK?

    If possible, I'd like to avoid using the SteamVR plugin, because it's causing conflicts with PlayStation builds and needs to be manually excluded when targeting that platform.
     
  2. DavidConsolo

    DavidConsolo

    Joined:
    Mar 28, 2015
    Posts:
    1
    Could you a manual calibration check in the beginning to subtract the "Intended Location" x,z transform from the HMD's x,z transform, and apply the inverse onto the HMD's transform?


    Quickly made this, might not work. I'm assuming the Controller (head) object has a parent with the transform reset to 0.

    Code (CSharp):
    1.  
    2. void Awake()
    3. {
    4. GameObject head_id=GameObject.Find("Controller (head)");
    5.  
    6. float intended_x=0;
    7. float intended_z=0;
    8.  
    9. float head_x = head_id.transform.position.x;
    10. float head_z = head_id.transform.position.z;
    11.  
    12. HMD.transform.parent.position = new Vector3 (intended_x - head_x, 0, intended_z - head_z);
    13. }
    14.  
     
  3. nickpettit

    nickpettit

    Joined:
    Dec 31, 2013
    Posts:
    33
    For anyone else struggling with creating seated experiences for OpenVR / Vive along with HMDs like Rift and other platforms like consoles, I figured this out. You can set the OpenVR tracking universe to seated by following these steps:
    1. Download the SteamVR plugin from the Asset Store and import it into your project.
    2. Find the openvr_api.cs file in Assets/SteamVR/Plugins and move the file somewhere else. I moved it to Assets/Plugins/x86_64 so that it's only included in x86_64 builds.
    3. If you're doing cross platform development, I found that deleting the SteamVR folder prevented a lot of conflicts with consoles. You only need the openvr_api.cs file if you're just doing a seated + gamepad VR game.
    4. In a script somewhere (probably where your other VR code is located) call this inside Awake(). If you're not targeting consoles or other platforms outside Win/Mac/Linux + editor, you can remove the define directives.
      Code (csharp):
      1. // Set tracking universe to seated for OpenVR.
      2. #if UNITY_STANDALONE || UNITY_EDITOR
      3.  Valve.VR.OpenVR.Compositor.SetTrackingSpace(Valve.VR.ETrackingUniverseOrigin.TrackingUniverseSeated);
      4. #endif
    And that's it. This allowed me to still use OpenVR in the editor and also create builds for Windows and consoles without conflicts. And the great part is, the rest of Unity's VR API works as expected. The recenter code works for both Rift and Vive once the OpenVR tracking universe is set properly. Like this...
    Code (csharp):
    1. InputTracking.Recenter();