我正在使用 Oculus Quest 开发 VR 场景。我需要在前面放置一个立方体,并在用户视线下方放置几个单位。当用户移动时,立方体必须移动。例如,如果用户转动或移动立方体,则用户通过始终保持在前面来确保其位置。我怎样才能做到这一点?
我应该采用 OVRCameraRig 位置和旋转并将其应用于立方体吗?但我从 StackOverflow 问题Unity3D Getting position of OVRCameraRig中读到 OVRCameraRig 不会移动,需要考虑 CenterEyeAnchor 细节。
我可以如下提取 CenterEyeAnchor 旋转和位置吗?
OVRCameraRig overCameraRig;
var position = overCameraRig.centerEyeAnchor.position;
var rotation = overCameraRig.centerEyeAnchor.rotation;
//OR should I use lines below?
var position = overCameraRig.centerEyeAnchor.transform.position;
var rotation = overCameraRig.centerEyeAnchor.transform.rotation;
如果要解决此问题,如何将提取的 CenterEyeAnchor 药水和旋转应用于立方体游戏对象?
我尝试了以下脚本并将其添加到多维数据集,但多维数据集没有随着用户移动而移动。
此外,我看到“测试位置”日志,但没有“正常”或“转换”日志。
public class MoveCube : MonoBehaviour
{
private OVRCameraRig overCameraRig;
public float offset = 10;
private GameObject itemObject;
private float distance = 3.0f;
// Update is called once per frame
void Update()
{
Debug.Log("Test position");
Debug.Log("Normal " +overCameraRig.centerEyeAnchor.position);
Debug.Log("Transform " + overCameraRig.centerEyeAnchor.transform.position);
if (itemObject != null)
{
itemObject.transform.position = overCameraRig.centerEyeAnchor.transform.position + overCameraRig.centerEyeAnchor.transform.forward * distance;
itemObject.transform.rotation = new Quaternion(0.0f, overCameraRig.centerEyeAnchor.transform.rotation.y, 0.0f, overCameraRig.centerEyeAnchor.transform.rotation.w);
}
}
}