Search Unity

Completely disable position tracking

Discussion in 'AR/VR (XR) Discussion' started by Cozywolf, Jan 12, 2017.

  1. Cozywolf

    Cozywolf

    Joined:
    Aug 1, 2016
    Posts:
    3
    Hi everyone

    I am doing a psychological research that requires me to present the visual stimulus on both Oculus Rift and HTC Vive. I am using Unity to build to experiment program, but to avoid any confounding, I have to disable position tracking.
    What I mean is that I am trying to treat the headset as a simple 3D display (pretend that I stick two images in front of it) that no head movement will be tracked (the position and rotation of the camera will always be 0,0,0).
    Could someone point me to which script I should modify to achieve this goal?

    Thanks a lot.
     
    keyrea1 likes this.
  2. NickAtUnity

    NickAtUnity

    Unity Technologies

    Joined:
    Sep 13, 2016
    Posts:
    84
    You can negate the default tracking pretty easily. First create a new game object and make it a parent of your camera. Be sure to zero out both transforms. Then attach this script to the parent game object:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.VR;
    3.  
    4. public class NegateTracking : MonoBehaviour
    5. {
    6.     void Update()
    7.     {
    8.         transform.position = -InputTracking.GetLocalPosition(VRNode.CenterEye);
    9.         transform.rotation = Quaternion.Inverse(InputTracking.GetLocalRotation(VRNode.CenterEye));
    10.     }
    11. }
    12.  
    That will give the parent the inverse transform of the camera effectively negating tracking, thus keeping the view in the HMD stable at the origin.
     
  3. Cozywolf

    Cozywolf

    Joined:
    Aug 1, 2016
    Posts:
    3
    It works, thanks a lot for the help.
    I am now facing another issue. Since I am going to generate the stimulus at a specific location (i.e. (0, 0, 50f)) when a key is pressed, but it seems that it the stimulus will be created based on (0,0,0) in the scene, which it appears off the center (and I can see that it tilts when I move my head).
    Is there a way for me to keep the stimulus at the center of the screen? (maybe constantly update the position of the stimulus?)

    Thanks a lot for the help
     
  4. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    Hi Nick,

    The solution above does away with the positional tracking but also with the neck modeling. (offset from your neck to your eyes) there is no parallax anymore when rotating your head. Would be good if we could access something in VRSettings to turn off tracking but still get some head modeling on the camera.

    thoughts on an intermediate solution?

    T
     
    MaartenDS likes this.
  5. Gizmoi

    Gizmoi

    Joined:
    Jan 9, 2013
    Posts:
    327
    Code (CSharp):
    1. UnityEngine.VR.InputTracking.disablePositionalTracking = true;
     
  6. w99_unity

    w99_unity

    Joined:
    Oct 13, 2017
    Posts:
    2
    Hi Nick, I happen do be working on something very similar to Cozywolf's project, and I was trying to get the soultion you gave to work, with no success. What exactly do you mean by "Be sure to zero out both transforms"? Any help would be appreciated.
     
  7. Matt_D_

    Matt_D_

    Joined:
    Jan 10, 2017
    Posts:
    6
    in 2017.2 you can now use the Tracked Pose Driver to apply only the rotation of a given pose. (or none at all by disabling the component).

    in revisions before 2017.2, using UnityEngine.VR.InputTracking.disablePositionalTracking = true; will stop position deltas being applied to the current "main" camera.
     
  8. w99_unity

    w99_unity

    Joined:
    Oct 13, 2017
    Posts:
    2
    Ok, I upgraded to 2017.2 and tried disabling the Tracked Pose Driver, but whenever I build and run the project it still keeps tracking the head position, is there any more specific info such as what object the script should be attached to or how to get the correct Tracked Pose Driver?

    Thanks!
     
  9. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    The Tracked Pose Driver (TPD) should be attached to the camera you are trying to stop the VR subsystem controlling
     
  10. walladev

    walladev

    Joined:
    Jan 15, 2017
    Posts:
    3
    When doing that, and disabling the TPD - The camera still seems to move (up and down) with a slight jitter. Do you have any idea why?
     
  11. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    Nope, please raise a bug on that. It's not something we've seen.
     
  12. jariwake

    jariwake

    Joined:
    Jun 2, 2017
    Posts:
    100
    Hi. I am trying to disable the head rotation tracking. I came across this thread and tried adding the Tracked Pose Driver component to my camera and disabling it, but that does not prevent HMD pose from setting the camera rotation. Is that possible in any way? I also tried doing transform.rotation = Quaternion.identity; in LateUpdate() and in PreRender(), but still the HMD pose overrides whatever I try to set as the rotation. Is this because under the hood Unity sets the rotation based on the HMD pose after PreRender is executed? Is there any way to prevent this?

    Im thinking maybe the rotation setting is prevented so that devs would never be able to take control over the camera rotation and therefore create a VR vomit generator 3000? =)

    I know it is unusual to force the camera rotation in a VR app, but it is necessary in my case - I am developing sort of a test application where in one mode I would need to ignore the real HMD pose and artificially set the camera rotation (and position)).
     
    Last edited: Oct 24, 2017
  13. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    The tracked pose driver should disable the auto update on the camera. There's a VR Device call, which takes the camera as a parameter. it only works if the TPD is on the camera object though.

    Even when the TPD is disabled, the automatic camera control is still disabled. Does this rotation apply still happen with a new empty project?
     
  14. ClaudiaKrog

    ClaudiaKrog

    Joined:
    Sep 30, 2017
    Posts:
    47
    Hey all,

    I need to disable VR position tracking, but keep rotation tracking, I'm using Unity 2018.2.11f1, will any of these solutions work for this version of Unity? Would you mind explaining how to do it?

    Thank you!!
    Claudia
     
    acrider likes this.
  15. Green-VR

    Green-VR

    Joined:
    Apr 15, 2013
    Posts:
    12
    using UnityEngine;
    using UnityEngine.XR;

    public class Trackingoff : MonoBehaviour
    {
    void Update()
    {
    transform.position = -InputTracking.GetLocalPosition(XRNode.CenterEye);
    //transform.rotation = Quaternion.Inverse(InputTracking.GetLocalRotation(XRNode.CenterEye));
    }
    }
     
  16. Green-VR

    Green-VR

    Joined:
    Apr 15, 2013
    Posts:
    12
    Hi, just a little update on the code to work with Unity 2018 . I,m making 360 still images with 3d object added. Its handy to use the vive to test things on the go.
     
  17. ClaudiaKrog

    ClaudiaKrog

    Joined:
    Sep 30, 2017
    Posts:
    47
    Thank you, I have tried this, but unfortunately it doesn't work - my camera still jumps up into the air by several feet
     
  18. Orion_78

    Orion_78

    Joined:
    Feb 13, 2014
    Posts:
    66
    Now it is UnityEngine.XR.InputTracking.disablePositionalTracking = true;
     
  19. acrider

    acrider

    Joined:
    Apr 28, 2016
    Posts:
    1
    I'm attempting the same thing as the people above. I've used:

    Code (CSharp):
    1.  UnityEngine.XR.InputTracking.disablePositionalTracking = true;
    and also attached a Tracked Pose Driver to all three cameras in the OVRCameraRig (LeftEyeAnchor, CenterEyeAnchor, RightEyeAnchor). So far, nothing disables the position tracking. I'm trying to get this working on an HTC Vive with 2018.2.10f1. Any suggestions?
     
  20. sudampatil

    sudampatil

    Joined:
    May 21, 2019
    Posts:
    1
    Hi, I have disabled for oculus quest.On OVRCameraRig prefab the OVRManager component has attached. OVRManager has provided UsePositionTracking properties. so you have to uncheck that.
    simple:).
     
  21. Matt_D_work

    Matt_D_work

    Unity Technologies

    Joined:
    Nov 30, 2016
    Posts:
    202
    Last edited: Jul 25, 2019
  22. Avinash190

    Avinash190

    Joined:
    Aug 19, 2017
    Posts:
    3


    It will reset the local rotation to 0,0,0.Is there a way to disable the tracking without resetting and have a the local rotation of the last frame
     
  23. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
    Code (CSharp):
    1.         public void SetTrackerActive( bool active )
    2.         {
    3.             StartCoroutine( DisableTracker( !active ) );
    4.         }
    5.  
    6.         private IEnumerator DisableTracker( bool disable )
    7.         {
    8.             XRDevice.DisableAutoXRCameraTracking( ActiveCamera, disable );
    9.             yield return null;
    10.  
    11.             ActiveCamera.gameObject.SetActive( false );
    12.             yield return null;
    13.  
    14.             ActiveCamera.gameObject.SetActive( true );
    15.         }
    16.  
     
  24. neomarian

    neomarian

    Joined:
    May 11, 2012
    Posts:
    43
    none is working in Unity 2019.2 for HTC Vive
     
    nani_unity302 likes this.
  25. tgaldi

    tgaldi

    Joined:
    Oct 28, 2015
    Posts:
    102
  26. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    @tgaldi
    I think I may be missing a question. Does the above code not work? In the old API XRDevice.DisableAutoXRCameraTracking is the API to use.

    In the new Plugin Architecture, simply not adding a Pose Driver should get you what you want.
     
  27. Audacity_Child

    Audacity_Child

    Joined:
    Feb 18, 2020
    Posts:
    4
    I'm trying to simply create a mini-map for my VR game and the camera keeps getting over written, ive found the GVR cardboard emulator script has a for loop to attach itself to any and every dern camera, so even with this...

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.VR;

    public class disabletracking : MonoBehaviour
    {
    void Update()
    {
    UnityEngine.XR.InputTracking.disablePositionalTracking = true;

    }
    }

    it still overrides my mini-map cam ive tried EVERYTHING, what am i missing?? I dont get any errors it just doesnt do what its being told :((((
     
  28. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    @Audacity_Child
    Have you tried calling XRDevice.DisableAutoXRCameraTracking?
     
  29. zvilich

    zvilich

    Joined:
    Jun 29, 2017
    Posts:
    6
    @StayTalm_Unity
    Hi,

    I am also doing some academic research in nuerophysiology when hampering the tracking.
    XRDevice.DisableAutoXRCameraTracking works
    and actually getting the tracking nodes to do my own tracking also works with the Unity 2018.3.2 TPD and Overriden BasePoseProvider.TryGetPoseFromProvider(EDIT* Verified also with a new 2019.3.9 Project with the XR legacy helpers)

    But changing the BasePoseProvider to return something different that expected gives jitters.
    Actually returning Pose.identity, that should have resulted in a frozen picture gives jitters when the Head is moving. stays put but jitters on movement.


    my goal:
    Pseudo code:
    InputTracking.GetNodeStates(nodes)
    foreach (XRNodeState x in nodes)
    {
    if (x.nodeType == XRNode.CenterEye)
    {

    Quaternion q;
    if (x.TryGetRotation(out q))
    {
    pose.transform.localRotation = Quaternion.Slerp(pose.transform.localRotation, q,delay);


    when delay is 1 everything is working.
    when delay is 0 it stays put but jitters.
    actually my main goal is the range between which appears great regarding delay manipulation except the jitters.
    The view in the PC monitor is perfect.

    It seems that there is something else that does further prediction which is not disabled.

    Thanks In advance
    (Using Vive with SteamVR)
     
    Last edited: May 7, 2020
  30. StayTalm_Unity

    StayTalm_Unity

    Unity Technologies

    Joined:
    May 3, 2017
    Posts:
    182
    Could be 'Asynchronous Reprojection' is getting you. It's a built-in trick that SteamVR (or Oculus or WMR) uses to get the most accurate view locations possible when rendering. Oculus describes it pretty well: https://developer.oculus.com/documentation/native/android/mobile-timewarp-overview/?locale=en_US

    Time Warp or Reprojection are SDK features, in SteamVR you can disable it via settings. It's not aware that you are head locked, and so it's trying to correct the headlocked image by making slight tweaks when you shake your head.

    This is a bug we should fix on our end and provide a cleaner headlocked setting. Feel free to report it.

    You may be able to work around it by re-enabling tracking, but parenting your gameplay content to the camera, this causes the objects to move and rotate with the camera and appear head locked. It won't work if you are using physics, sadly. You can also disable the Asynchronous Reprojection in SteamVR, but that's not very intuitive. If neither of those solutions work for your case report the bug and I'll see if we can disable reprojection internally for each SDK.
     
  31. drakfyre

    drakfyre

    Joined:
    Oct 6, 2011
    Posts:
    6
    Both types of reprojection are disabled on my machine; in fact, they can't *be* enabled on my headset (Quest via Virtual Desktop). But I'm still getting this jitter when I have a Tracked Pose Driver attached to my Main Camera. The only way to solve it is to *not* use the Tracked Pose Driver. XRDevice.DisableAutoXRCameraTracking(camera,true) did nothing to solve the problem.

    There is clearly a bug here. Tested on OpenVR. Unity version 2019.3.15f1 using the new Input System.
     
    Last edited: Jun 3, 2020
  32. drakfyre

    drakfyre

    Joined:
    Oct 6, 2011
    Posts:
    6
    Further info: the bug only occurs using the new Input System Tracked Pose Driver. The one in the Legacy XR Input System does *not* have the problem. Again, this is on unity version 2019.3.15f1, tested on OpenVR.

    I've created a repository that exhibits the bug, it is the most basic example I could make; just look at the horizon and move your head around and you'll see a jitter. If you remove the Tracked Pose Driver, the jitter goes away and the horizon is stable when moving your head.

    https://github.com/PushyPixels/UnityVRTrackedPoseBug
     
  33. texone

    texone

    Joined:
    Jan 26, 2018
    Posts:
    12
    I have the same issues looks like XR is messing with any cameras projection matrix, I wrote a small script that clearly shows this.
     
  34. Forster-Xia

    Forster-Xia

    Joined:
    Dec 26, 2018
    Posts:
    3
    Hi guys, my solution is to set original cameras false, create new one, and use code below in Start():
    Code (CSharp):
    1. UnityEngine.XR.InputTracking.disablePositionalTracking = true;
    upload_2020-6-23_16-51-7.png
    (FirstAnchor is a copy of CenterEyeAnchor)
    BTW, DO NOT uncheck these 2 options(Use Position Tracking; Use IPD in Position Tracking) in OVR Manager, or the display in HMD will go wrong.
    Then you shall have a fixed Head Camera and tracked hands :)
     
    Last edited: Jun 23, 2020
  35. Aksotroth

    Aksotroth

    Joined:
    Jul 8, 2014
    Posts:
    5
  36. devotionsolutions

    devotionsolutions

    Joined:
    Feb 9, 2013
    Posts:
    40
    Hello everyone, I've trying the different alternatives here with no much luck.
    What I'm trying to do is avoiding the user movement (not the head tracking/rotation). I.e.: if the user takes a step, avoid that movement.
    I'm Using Unity 2020.1.9f1 + Oculus Quest 2.
    Any idea?
     
    wm-VR likes this.
  37. siderskiy

    siderskiy

    Joined:
    Mar 13, 2020
    Posts:
    1
    Hello everyone,

    I'm working on a physiology experiment where I still need the head tracking data to change the camera position, just not 1-to-1.

    I'm using DisableAutoXRCameraTracking in Start() as mentioned above, with 2019.4 / LTS. That works. Thanks @StayTalm_Unity
    This allows me to still read the HMD coordinates, and move the camera myself.
    But it's a little jumpy, any ideas?

    Ex:


    public Camera childCamera;

    UnityEngine.XR.InputDevice ViveHDM;
    UnityEngine.Vector3 ViveHMDVelocity;

    void Awake()
    {
    XRDevice.DisableAutoXRCameraTracking(childCamera,true)
    }

    void Start()
    {
    ViveHMD = findVive(); //my own function, it works
    }

    void Update()
    {
    ViveHMD.TryGetFeatureValue(UnityEngine.XR.CommonUsages.centerEyeVelocity, out ViveHMDVelocity);

    //Now move the camera yourself, but it's not smooth. Why?
    transform.Rotate(RotateAmount * Time.deltaTime);
    }


    P.S.
    I liked the negating tracking idea (from @NickAtUnity) of the parent object but had to change the code for the math to work out, but it was flickering. I don't really know how the HMD data and the Camera movement data is connected, but if someone knows, this would work:
    transform.rotation = Quaternion.Inverse(ViveHMDRotation);
    transform.position = -(transform.rotation * ViveHMDPosition);
     
    Last edited: Jan 9, 2021
  38. jolanbar

    jolanbar

    Joined:
    Sep 23, 2019
    Posts:
    6
    Hey everyone,

    I'm also looking to disable the positional tracking for the Oculus Rift S Headset. I'm using Unity 2020.3.4f1 and the Oculus Integration Asset version 27.0 which is the latest.

    I tried almost all the posted solution above and none of them is working. My scene just contain the OVRCameraRig prefab from the oculus integration asset and a 3D cube.

    The things I tried :
    - Disabling the "Use Position Tracking" checkbox of the OVRManager but this cause huge rendering issue.
    - Calling XRDevice.DisableAutoXRCameraTracking(centerCam, true) that did literally nothing, even with the trick of disabling and re-enabling the camera posted by @tgaldi
    - Setting StereoTargetEyeMask to None on the centerCam as suggested by @Aksotroth
    - Tried to call UnityEngine.XR.InputTracking.disablePositionalTracking = true; but this is deprecated in my unity version, and it did nothing.
    There is only 1 way I managed to make it work is by editing the OVRCameraRig script of the oculus integration asset, on the line 182 in the UpdateAnchors function, I changed this :
    centerEyeAnchor.localPosition = centerEyePosition;
    to this :
    centerEyeAnchor.localPosition = Vector3.zero;

    Then the rotational tracking was working, but the positional tracking was disabled.
    I don't like this way at all because I have to change things in the oculus integration asset, so if anyone has a better way of doing it, please tell me !

    I guess the issue is not coming from Unity but from Oculus, they need to update their script to allow such a simple option.
     
    majdhuzi, dekatron1 and brodycreate like this.
  39. Realizator

    Realizator

    Joined:
    Nov 13, 2020
    Posts:
    1
    jolanbar thank you for your tip! I used this approach to turn off rotational tracking, by replacing this row:
    centerEyeAnchor.localRotation = centerEyeRotation;

    to this:
    centerEyeAnchor.localRotation = new Quaternion(0f, 0f, 0f, 0f);

    in OVRCameraRig script.
    By the way, "Use position tracking" checkbox works fine for me in OVRManager.

    BTW, in OVRManager.cs you can find this code:
    [HideInInspector]
    public bool useRotationTracking = true;

    By commenting the first row [HideInInspector] you can see this checkbox in OVRManager, but turning this off gets a lot of issues to me.

    So your solution was the only working way for me. Thanx!
     
  40. parixit2411

    parixit2411

    Joined:
    Nov 10, 2021
    Posts:
    12
    I am using the XR interaction toolkit (2.2.0). I want to disable the headset position movement but still want the controller to behave properly. Currently, my headset is working fine but my controller has a vertical offset from the actual controller.
    Because the offset controller appears above my head in VR.

    My setup :
    - XR Origin
    - Main Camera with Tracked Pose Driver, the tracking type is set to Rotation only.
    - On the main camera, I also have a script with DisableAutoXRCameraTracking in the Start.

    How can I fix this?
     
  41. Max_Bol

    Max_Bol

    Joined:
    May 12, 2014
    Posts:
    168
    The controllers doesn't use the Headset as their origin, but an interpolation of the "world" calculated by the headset. so, when you set the headset to Rotation Only, it basically freeze the headset position, but the controllers are still updating from the 3D real world. (The center of that interpolated world is kinda vague as it depends on how the headset is set.)

    The following method works if you work with the XR setup with Action-based controllers.

    I think your best bet if you go with the Rotation only tracking method:
    1) Turn off the the check mark of the "Position Action" on your controllers game object's XR Controller script.
    This will turn off the default world's based tracking of the controller.

    2) Write a new script that will be placed on each controller.
    You got to create a reference, in that script, to the VR camera. (Camera.Main should work if you use the default VR camera.) You can get your controllers' position from the "XRI Default Input Actions". If you unsure how to set it up, open the "ActionBasedController.cs" script (it's the one which move your in-game controllers). There's a bit of workaround, but the process is relatively straight forward. The only problem with reading that file is that it covers so many things, you got to know how to trim the information.

    Still, you should be able (if you know what you're doing) to extract the bits of codes that allows you to get the position from the "XRI Default Input Actions" which gives you the real-world Vector3 position of a controller from the headset perspective.

    3) Before applying the the position to the controllers in-game transform, calculate the relative position between the Vector3 position of each controller and the headset Vector3 position (all in real-world by looking up the "XRI Default Input Actions" which read and store the position and rotation detected by the device.). After, this should allow you to apply the position based on the headset position and not the real world position for each individual controller.
     
  42. brodycreate

    brodycreate

    Joined:
    Dec 7, 2020
    Posts:
    2
    Thanks!