Forum Discussion
ziphnor
10 years agoExpert Protege
Combining Oculus and perception neuron integrations
Hi, First off a disclaimer: I am a complete noob when it comes to Unity, i only downloaded Unity to try to setup a simple VR demo combining my DK2 with my Perception Neuron tracking suit. I do work...
Anonymous
10 years agoNot applicable

just make the main camera a child of the head. make sure you have 'Virtual Reality Supported' checked in the Player settings. If you want to only use orientation tracking, disconnect the webcam. (The DK2 works without a webcam)
Try this script to disable translation/rotation of your HMD by adding it to MainCamera.
using UnityEngine;
using System.Collections;
/// <summary>
/// selectively lock axes of an HMD to prevent motion
/// </summary>
public class HmdLock : MonoBehaviour
{
public bool rollLock, pitchLock, yawLock;
public bool xLock, yLock, zLock;
private Vector3 lastPosn;
private Quaternion lastRotation;
// Use this for initialization
void Start()
{
lastPosn = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye);
lastRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye);
}
// Update is called once per frame
void Update()
{
if (rollLock || pitchLock || yawLock)
{
// undo rotation change since last frame
Vector3 rotationChangeEulers = new Vector3(0f, this.transform.parent.rotation.y, 0f); // undo Y-rotation of body
Vector3 rotationInverse = new Vector3();
if (rollLock)
{
rotationInverse.z = -rotationChangeEulers.z;
}
if (pitchLock)
{
rotationInverse.x = -rotationChangeEulers.x;
}
if (yawLock)
{
rotationInverse.y = -rotationChangeEulers.y;
}
this.gameObject.transform.Rotate(rotationInverse, Space.World);
}
if ((xLock || yLock || zLock))
{
// undo position change since last frame
Vector3 currentPosition = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye);
Vector3 positionChange = currentPosition;
if (!xLock)
{
positionChange.x = 0f;
}
if (!yLock)
{
positionChange.y = 0f;
}
if (!zLock)
{
positionChange.z = 0f;
}
//this.gameObject.transform.Translate(positionChange, Space.Self);
this.gameObject.transform.localPosition = -positionChange;
}
// update last frame
lastPosn = UnityEngine.VR.InputTracking.GetLocalPosition(UnityEngine.VR.VRNode.CenterEye);
lastRotation = UnityEngine.VR.InputTracking.GetLocalRotation(UnityEngine.VR.VRNode.CenterEye);
}
/// <summary>
/// Compute the relative rotation between two quaternions. This is done by computing the conjugate of the reference quaternion and multiplying by the other quaternion.
/// </summary>
/// <param name="reference">angle relative to which the result should be calculated.</param>
/// <param name="other"></param>
/// <returns>The angle that 'reference' would need to be rotated through to get 'other'</returns>
private static Quaternion RelativeOrientation(Quaternion reference, Quaternion other)
{
Quaternion resultant;
Quaternion conjugate = new Quaternion
(
-reference.x,
-reference.y,
-reference.z,
reference.w
);
resultant = other * conjugate;
return resultant;
}
public void ResetCorrection()
{
this.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f);
this.transform.localRotation = Quaternion.identity;
}
}
Quick Links
- Horizon Developer Support
- Quest User Forums
- Troubleshooting Forum for problems with a game or app
- Quest Support for problems with your device
Other Meta Support
Related Content
- 6 years ago
- 7 years ago