So with the new VR support the main camera's transform is being overridden with the Oculus transform.
I kinda get this in a general use case but I need to able to override this behaviour.
Specifically I want to override the orientation so that the real world Oculus orientation maps to a greater in-game orientation, particularly on the local y-axis i.e. when I turn my head 90 degrees in the real world, I want to be facing 180 degrees in game.
This is something I have done before in VR on other engines and is a critical part of many locomotion systems you'll see being used.
So how do I go about this, I understand I could always child the camera to a parent and then rotate the parent using the Oculus orientation as a base but this is messy and a bit of a quaternion nightmare.
What have you tried?
I've just simply adjusting the camera transform in many positions of the game update, Update(), LateUpdate() etc... but in every case the new transform I set is simply stamped over.
Currently I have a reasonable solution whereby the camera is parented to another transform, in that transforms' update I take the orientation of the oculus, extract the yaw component. I then create a new create a new quaternion with the desired increase in yaw around the transforms up axis and set this to be the rotation.
This works but does break on occasion and also taking the transform of a child to populate a parent is just awful.
I simply want to be able to intercept the oculus orientation and modify it before it gets applied to the camera.
Answer by zachduer
Oct 24, 2016 at 10:16 PM
Took a few minutes to figure out, but in case anyone in posterity is curious, here's how:
The OVRPlugin class has boolean properties for both position and rotation. Setting these properties in turn calls methods in the oculus plugin itself to enable and disable the position and orientation tracking. Setting rotation in OVRPlugin to false (or, more tediously, getting a reference to the oculus plugin and calling its method: ovrp_SetTrackingOrientationEnabled(false)) will disable rotation transformations from being applied to the camera in Unity.
You can find this at lines 425-435 of the OVRPlugin.cs script that comes in that unitypackage.
The above is true for version 1.8 of Oculus Utilities for Unity 5.
(In retrospect, I realize I'm not 100% answering the question of the OP, as I'm not intercepting the rotation values, but rather disabling them entirely (which is what I needed for my own purpose)).
I know, this thread is a bit older, but I have nearly the same problem right now on my own.
For me, this is not working. I tried it with the Oculus Utilities 1.8 and Unity 5. Can you provide a project with which I can test it out?
Thanks in advance.
Roetka, what exactly are you trying to accomplish?
I need to deactivate the whole tracking of the HMD. In my case I need to deactivate the tracking because I want to use another MoCap System.
Great! I'm doing the exact same thing.
Here is a simplified project that disables both position and rotation from the Oculus. https://drive.google.com/file/d/0B38bbn4KOP60MFliVmhBUkFjbnM/view?usp=sharing
Additionally, though, I will note that I have had best success when using the rotation from the Oculus and the position from the mocap system. The latency from the mocap system is always going to be higher than that of the IMU built into the headset. In this case, you don't need to mess with any scripts at all. In OVRManager, just turn of UsePositionTracking, and then cover the sensor with a piece of tape to double-down and make sure it doesn't send any position data. Then, send your mocap position data to the TrackingSpace transform. The last thing you'll need to do is align the axes of the mocap system with the axes of the IMU rotation. To do that, make a simple script that that calls VR.InputTracking.Recenter(); And maybe have it do that when you press spacebar, or some other hotkey. Then, when you start up, aim the headset toward Z+ in your mocap space and activate that Recenter call, and you'll be set to go. Note that the gyros in the IMU do drift, so you may need to do this every so often during a session.
I've made two scenes in the example project... one to disable all OVR tracking, and one to use rotation from OVR and position from mocap system. It's slightly abstracted because I didn't want to include my own mocap code.
Hope that helps!
@zachduer, thanks for sharing the project. I tried to run it and i would like to do the same as you mentioned. I would like to use the position of the Mocap system (Xsens) and use the orientation of the Oculus. Now I tried the small scene you added "UseOVRRotation". The only thing i'm bumping into is actually attaching it to my Mocap system. Well, attaching works by just draging it onto the neck for example, but i can't get to at that location once booting the game. Could you give a dumbed down explanation on how to get that to work please? Do keep in mind that i'm not much of a programmer, so much of this is pretty new to me.
I've never had a chance to use the Xsens suits, so it's possible my reply may not be suitable.
I don't quite understand what you mean that you're not able to "get at that location once booting the game." However, it sounds like what you're trying to do is apply the OVR camera to the head of an avatar that's part of the mocap controlled avatar. This is different than what I'm doing. I'm not using a full avatar; I have a virtual camera being positioned based on the location of a single rigid body. It's unclear to me exactly what you're saying, but I'll take a guess: If you're attaching your camera to the head of your avatar that's part of a skeleton driven by the mocap system, it might be tricky to turn off the mocap rotation of that part of the skeleton and instead use the rotation of the IMU. As a test, I would recommend pulling the camera out of that hierarchy and instead first just try setting its position and rotation to whatever the coordinates are from the mocap, separated from the rest of the skeleton. If that works, go from there, trying to disable the rotation from mocap and use the IMU of the Oculus.
Or, if I'm misunderstanding, please feel free to clarify.
Thanks for the reply. What you are saying is indeed what i'm trying, although i'm not attaching the OVR to the head, but to the neck. I would like to use the orientation of the Oculus instead of the IMU's.
The problem i'm encountering is on how to attach your version to a bone? I'm not a programmer, so most if this is pretty new.
Can I just add a rigid body to the neck and attach the OVR to that?
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
8 People are following this question.
Set skateboard (gameobject) to rotate with OVR camera
Rotating around an object
Camera rotation vmware
2D camera rotating relatively to game object speed
1st person Camera rotates suddenly in another direction when unparenting from a platform