Logic1
Logic1

Reputation: 1847

Disabling head-tracking on a SteamVR camera in Unity?

I am trying to develop a HUD for my VR players using two cameras. One is a stationary camera that points at my HUD objects with a depth=1, the other is the main camera with depth=0 which tracks the HMD and has the HUD overlaid onto it.

However Unity, SteamVR or OpenVR is forcing my camera to track the player's HMD. After my exhaustive search I was unable to find any way to stop this behavior. Then I tried to parent all of my HUD objects to my HUD camera and hoped for the best.

This results in undesirable jerky motion in all HUD objects:

Project Hierarchy:

[WorldHUD]
    |__ Container (HUD) 
        |__ Camera (eye)
            |__ TextMesh (Status) <- Is child of camera

[CameraRig]
    |__ Camera (Head) 
        |__ Camera (eye)

[SteamVR]

I believe I really need control over my camera's transform so I may prevent it from moving or stopping it from tracking the player's HMD.

I have tried updating the cameras position in Update() and LateUpdate() but that does not have any affect. I also spent many hours modifying/debugging SteamVR and OVR scripts which had no positive results and the cameras never stopped tracking.

I have tried using this suggested script on my cameras parent:

NegateTracking.cs:

using UnityEngine;
using UnityEngine.VR;

public class NegateTracking : MonoBehaviour
{
    void LateUpdate()
    {
        transform.position = -InputTracking.GetLocalPosition(VRNode.CenterEye);
        transform.rotation = Quaternion.Inverse(InputTracking.GetLocalRotation(VRNode.CenterEye));
    }
}

This caused the camera to point in one direction but was still translating a bit. However I noticed that things seemed even more choppy this way and feel I'm either using it wrong or it just isn't sufficient.

I'm now back to looking for ways to disable headtracking on certain cameras so I am able to position them in my scene.

Does anyone know how SteamVR/OpenVR takes control of these camera's transforms? Is there any way to disable or overridden this behavior?

Thank you.

Upvotes: 0

Views: 5130

Answers (2)

dljava
dljava

Reputation: 1856

Or you can change the target display and the target type (to main display) in your Camera component. (can also be done in a script)

Upvotes: 0

Logic1
Logic1

Reputation: 1847

So, just spent the whole night developing a functional workaround and put together a project that uses a little post processing magic to essentially "spoof" a stationary camera. My idea was to generate two renderTextures from a custom stereo camera setup consisting of two separate cameras that are not being tracked (which allows control of position, rotation, convergence plane. fov and so on). I then pass those camera's (left and right) renderTextures to the left and right eyes of one of the "tracked" cameras within the OnRenderImage() function. It worked better than I expected, So I decided to put everything up on GitHub and write a short tutorial for anyone else needing to do this.

Stationary Stereo Camera (Download From GitHub) enter image description here

Upvotes: 1

Related Questions