Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 ez9002 · Oct 13, 2021 at 07:07 PM · scripting problemvrcharacter controlleroculus

Script for syncing Oculus VR player position with VR headset not working as intended

I've been running into countless issues trying to get the HMD location to sync with the character controller (as my teleport location, and rotation functions rotate the center of the character controller, which the HMD can get offset from in roomscale). I'm using the Oculus OVR player controller. My pseudocode basically looks like this:

 void Update() {
     OVRPlayerLocation = (currentLocation.x + offset.x, currentLocationY, currentLocation.z + offset.z);
 }
  
 Void LateUpdate() {
     Offset = currentHMDLocation;
 }

I'm getting the currentHMDLocation by getting the local position of the centerEyeAnchor, which follows the headset in roomscale.

But the player is instead sliding around the map until they hit a wall, often at very high speeds. I think this could be an issue with the player collider pushing the player back (an issue I had when I was implementing teleportation), but my solution there, where I would disable then re-enable the player character controller, doesn't work here.

I've been stuck on this issue for days and haven't been able to find a solution that doesn't involve switching to the XR rig, which isn't an option for this project unfortunately. Can anyone point me in the right direction?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by rh_galaxy · Oct 13, 2021 at 08:06 PM

First I have never used OVRPlayer... Where in the object hierarchy have you put the OVRPlayer? Maybe you need to work in world space?

This is how I deal with the hand controller position and rotation which is put in a CameraHolder object that in itself can move and rotate, I have also put the MainCamera here which follows the HMD because of the TrackedPoseDriver component.

alt text

 using UnityEngine.XR;
 using UnityEngine.InputSystem;
     
 //head world pos directly from camera
 Vector3 vHeadPosition = Camera.main.transform.position;
 Vector3 vHeadDirection = Camera.main.transform.forward;
 Quaternion qHeadRotation = Camera.main.transform.rotation;
     
 //right hand
 UnityEngine.XR.InputDevice handRDevice = InputDevices.GetDeviceAtXRNode(XRNode.RightHand);
 bool posRSupported = handRDevice.TryGetFeatureValue(
     UnityEngine.XR.CommonUsages.devicePosition, out Vector3 posR);
 Vector3 vRHandPosition = transform.TransformPoint(posR); //to world coords
 //                       ^CameraHolder obj
 bool rotRSupported = handRDevice.TryGetFeatureValue(
     UnityEngine.XR.CommonUsages.deviceRotation, out Quaternion rotR);
 Vector3 vRHandDirection = rotR * Vector3.forward;
 vRHandDirection = transform.TransformDirection(vRHandDirection);
 Quaternion qRHandRotation = Quaternion.LookRotation(vRHandDirection);

Maybe you need an OVRPlayerHolder that you teleport and rotate however you like and leave the player (i.e camera) alone? But if the player moves into a wall you may need to handle that by pushing back the holder, but never touch the HMD coordinates.


If you really want to do like a recenter of the HMD after a teleport to get the camera facing in a new direction, you could compensate with the opposite movement and rotation in the holder object (-x_pos, -z_pos) (-y_rotate).


maincamera1.jpg (129.9 kB)
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

268 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 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 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

[Oculus SDK] How to add colliders to OVRGrabbable at runtime? 2 Answers

How to enable/disable VR from code? 0 Answers

How to stop a video using the OCULUS script MoviePlayerSample.CS. 0 Answers

Does Oculus Go still require importing Oculus libraries? 0 Answers

Pulling Object forwards and back "Oculus VR" 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