我是Unity(和VR)的新手,正在尝试在 Google Cardboard 上设置一个小例子,在这个例子中,我有一个模型,当用户转动头部时它也跟随着转动 - 类似于 Google Cardboard 应用程序中的面罩演示。因此,当用户向上看时,模型向上旋转,向左看时,模型向左旋转等等。
我的场景目前有一个名为CardboardMain的对象和我的3D模型。我已经将Cardboard Head脚本附加到我的模型上,现在它能够正确地随着头部运动而旋转。但是还需要让该对象保持在相机前方。
为了实现这个功能,我创建了一个脚本,并将其附加到了我的3D模型上。该脚本看起来像这样:
using UnityEngine;
using System.Collections;
public class lookAtMe : MonoBehaviour {
private CardboardHead head;
private Vector3 offset;
public GameObject scrimshaw;
// Use this for initialization
void Start () {
head = Camera.main.GetComponent<StereoController>().Head;
scrimshaw = GameObject.FindGameObjectWithTag ("Scrimshaw");
}
// Update at end of frame
void LateUpdate () {
// head.transform.position = the positon of the head on the plane
// head.Gaze.direction = positon of where the head is looking
offset = head.Gaze.direction + head.transform.position;
scrimshaw.transform.position = scrimshaw.transform.position + offset;
}
}
然而,我的模型位置没有改变。我本以为如果我为
transform.position
提供一个新的向量3,它会相应地移动对象。还有其他方法吗?我尝试在Main Camera实例上应用
transform.LookAt(target)
,将目标设置为模型。虽然这种方法确实有效,但太过突兀,不能使用。