Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KdRWaylander · Feb 19, 2018 at 05:18 PM · script.vrsteamtweaking

SteamVR: tweak update poses (fake tracking latency)

Hi,


Unity version: 2017.1.0f3


I'm willing to simulate latency in the head tracking of my Oculus: when one moves the head, the image should but updated a few ms later and not "immediately".


Since SteamVR_UpdatePoses is deprecated, the script that handles head position is SteamVR_Render.cs. Here are the lines that seems to be related to the tracking:


 // [...]
 
 public TrackedDevicePose_t[] poses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
 public TrackedDevicePose_t[] gamePoses = new TrackedDevicePose_t[0];
 
 // [...]
 
 public void UpdatePoses()
 {
     var compositor = OpenVR.Compositor;
     if (compositor != null)
     {
         compositor.GetLastPoses(poses, gamePoses);
         SteamVR_Events.NewPoses.Send(poses);
         SteamVR_Events.NewPosesApplied.Send();
     }
  }
 
 void OnBeforeRender()
 {
     UpdatePoses();
 }



Here is what I tried:

 // [...]
 
 public TrackedDevicePose_t[] poses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount];
 public TrackedDevicePose_t[] gamePoses = new TrackedDevicePose_t[0];
 
 // [...]
 
 public void UpdatePoses()
 {
      var compositor = OpenVR.Compositor;
      if (compositor != null)
      {
         compositor.GetLastPoses(poses, gamePoses);
         SteamVR_Events.NewPoses.Send(poses);
         SteamVR_Events.NewPosesApplied.Send();
      }
 }
 
 void OnBeforeRender()
 {
      StartCoroutine(Lag());
 }
 
 private IEnumerator Lag()
 {
      yield return new WaitForSeconds(1f);
      UpdatePoses();
 }

 

As you can see, i only store the current position/rotation values and wait for a given time (1 second here but much less in actual development) before updating the camera transform.


When I try to make a non-tracked object follow (with lag) a tracked object with a similar piece of code (same coroutine system), it DOES work perfectly. However, when I apply my code (coroutine) directly (as above) to the tracking: nothing changes. The object moves in "real time" despite the "custom" tracking, as if I did not tweak anything.


My question is then: has anyone already played with the SteamVR tracking and/or can anyone point me what I am missing ? Or maybe there is an other way to cheat the tracking system of a VR headset ?


Cheers,


KdRWaylander

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cengi · Oct 15, 2018 at 06:15 PM 0
Share

We had a hard time figuring this out until we saw your simple explanation! We are working on an experiment at our university for a course, so with the deadline approaching we thought we wouldn't make it. Thank you so much!

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by KdRWaylander · Mar 13, 2018 at 12:12 PM

Here is the workaround I found (I was never able to tweak directly the tracking system):


  • I added an other camera with a higher depth and a target eye parameter set to "Both" in my scene. See this post that describes how to have 2 cameras in a scene.

  • I added a script on my new camera that makes the camera follow the SteamVR camera after a given amount of time (see below). This may be done differently (for exemple with a position buffer) and this may not be optimized but anyhow, it works.

  • I added the Tracked Pose Driver component (available since v2017.3 at least, maybe v2017.2) and then DISABLED IT. It is important to do so, this allows to make Unity understand that it must not override the position of the object (it seems to do so by default if there's a Camera component on the gameobject)

  • Lastly, i added the same Tracked Pose Driver component on the SteamVR camera (unless what nothing would move, I don't know why)


My follow script (C#):

 using System.Collections.Generic;
 using UnityEngine;
 
 public class FollowWithLag : MonoBehaviour {
     [SerializeField] Transform  m_targetToFollow;
     [SerializeField] bool       m_lag;
     [SerializeField] float      m_lagTime;
 
     Vector3     m_targetPosition;
     Quaternion  m_targetRotation;
 
     void Update()
     {
         if (Input.GetKeyDown(KeyCode.L))
         {
             m_lag = !m_lag;
         }
     }
 
     void LateUpdate ()
     {
         m_targetPosition = new Vector3(m_targetToFollow.position.x, m_targetToFollow.position.y, m_targetToFollow.position.z);
         m_targetRotation = m_targetToFollow.transform.rotation;
 
         if (m_lag && m_lagTime != 0)
         {
             StartCoroutine(LaggyFollow(m_targetPosition, m_targetRotation));
         }
         else if (!m_lag || m_lagTime == 0)
         {
             transform.position = m_targetPosition;
             transform.rotation = m_targetRotation;
         }
     }
 
     private IEnumerator LaggyFollow(Vector3 _pos, Quaternion _rot)
     {
         yield return new WaitForSeconds(m_lagTime/1000f);
         transform.position = _pos;
         transform.rotation = _rot;
     }
 }



Hope this helps someone one day.

Waylander

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Cengi · Oct 15, 2018 at 10:04 PM 0
Share

We had a hard time figuring this out until we saw your simple explanation! We are working on an experiment at our university for a course, so with the deadline approaching we thought we wouldn't make it. Thank you so much!

avatar image z19941225110 · Sep 24, 2019 at 05:45 PM 0
Share

Can I supplement your answer? For the original camera, in the "camera" component, set the "culling mask" as "nothing" to improve performance.

avatar image
0

Answer by yugen1 · Aug 04, 2020 at 08:57 AM

For people still looking at this issue, the script below does the lag part very efficiently

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class CameraFollow : MonoBehaviour
 {
     public Transform mainCam; //this would be VR Camera or AR camera
     public float delay = 0.5f;
 
 
     public Camera camera; //this would be the 2nd added camera
     private struct PointInSpace
     {
         public Vector3 Position;
         public float Time;
 
     }
 
     private Queue<PointInSpace> pointsInSpace = new Queue<PointInSpace>();
 
 
     void FixedUpdate()
     {
         // Add the current target position to the list of positions
         pointsInSpace.Enqueue(new PointInSpace() { Position = mainCam.position, Time = Time.time });
 
         // Move the camera to the position of the target X seconds ago 
         while (pointsInSpace.Count > 0 && pointsInSpace.Peek().Time <= Time.time - delay + Mathf.Epsilon)
         {
             transform.position = pointsInSpace.Dequeue().Position;
         }
     }
 }
 

However, this works only in Unity editor for AR cases, which I am looking into. @KdRWaylander if you have any suggestion or idea please let us know.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Steam VR : Make latency 0 Answers

HTC Vive Camera Height [VRTK] [Steam VR] [Open VR] 1 Answer

Is it possible to access SteamVR settings with a script? 0 Answers

SteamVR 2.2 Change hand pose without interacting with an object 1 Answer

How do I switch levels when the user grabs an object in SteamVR? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges