r/oculusdev • u/BullockHouse • Aug 31 '14
Capturing raw head position in Unity
Hey guys! I'm getting started with Unity and the DK2, and I'm trying to figure out how to get the raw position of the camera from the OVRCameraController prefab. I'd like to hang the body from it on a spring (as a kind of pseudo inverse-kinematics), but simply hanging it from one of the eye cameras causes problems during head rotation. What I'd like is just to be able to script an empty game object to stick to the position of the head (as returned by the camera) and then hang the body off it. Anybody know of a way to do that?
1
u/mptp Aug 31 '14
Just have a script that has something like
Transform cameraOVR;
public static Vector3 cameraPos;declared in the class, and
cameraOVR = GameObject.Find("OVRCameraController") as Transform;in Start(). Then in Update() you have something like
cameraPos = cameraOVR.position;Then whenever you want you can just call newScript.cameraPos to get the camera position.
edit: assuming you're using C#. If you're using Javascript you're on your own.
1
u/BullockHouse Aug 31 '14
Thanks! Unfortunately, it doesn't seem to be working: cameraOVR.position always returns the same value (the starting position of the camera). Furthermore, directly parenting the camera tracker prop to the OVRCameraController prefab also shows no movement. Any thoughts on what might be wrong?
1
u/mptp Sep 01 '14
I'm not gonna lie, I haven't gotten my DK2 yet so I've not played with the unity SDK yet. But I would imagine that there will be some transform that's moving to match the positional tracking, so it's just a matter of finding it and getting it's transform.position vector each frame
1
u/kidego Sep 01 '14
Have you posted your question in Unity Integration on the OVR dev forums? The OVR devs are very helpful with this kind of stuff.
https://developer.oculusvr.com/forums/viewforum.php?f=37&sid=bd4fad09c7e6040e409fa10b96e00810
2
u/BullockHouse Sep 01 '14
UPDATE:
So, I eventually solved this. The code below appears to work:
public Vector3 headposition;
public Quaternion orientation;
OVRDevice.GetCameraPositionOrientation(ref headposition, ref orientation);
This will date the headposition and orientation variables with the correct values.