通过头部 VR 纸板引导对象
Steering object by head VR Cardboard
有人可以告诉我如何进行基于头部的转向吗?我知道如何在只移动相机时做到这一点,但我想通过头部和相机移动物体以跟随物体。
我需要这个,因为我想为对象实现游戏逻辑(如果我可以将相机视为普通对象,它对我也适用)。
我找到了这个仅用于转向相机的代码:
public float speed = /* some number */;
private CardboardHead head;
void Start()
{
head = // find the CardboardHead
// example:
// head = Camera.main.GetComponent<StereoController>().Head;
// or, make the variable public and use drag-and-drop in the Editor
}
void Update()
{
transform.position += speed * head.Gaze.direction;
}
我开始做游戏是为了团结,所以如果我有什么错误,请指正。
您是否在此处使用适用于 Unity 的 Cardboard 插件?
https://developers.google.com/cardboard/unity/download
如果你这样做,那么有一个名为cardboard main的预制件,将它放在场景中,然后如果你看到其中有一个名为Head
的游戏object,它包含CardboardHead
脚本。所以这是你的脚本:
public GameObject head; // drag the Head gameobject to here or you can just get it from the start
void Start()
{
if (!head) // if you didn't drag the gameobject
{
head = FindObjectOfType<CardboardHead>().gameObject;
}
}
void Update()
{
transform.position += speed * head.transform.forward; // it is better to multiply by Time.deltaTime
}
另外,为什么它被标记为 Java?
新问题:
这就是我所做的。我拆分了 'visual' 和 'mechanic'。我从播放器中删除了网格渲染器,冻结了刚体的旋转。我为 'visual' 创建了一个新的 child 它有一个名为 Rotate.cs
的脚本并删除了它的碰撞器。
脚本更改:
在 Forward.cs
中使用 rb.AddForce(transform.forward * speed);
返回,在 Rotate.cs
中使用
void Update () {
transform.Rotate(Vector3.right * 5);
}
这是我能想到的最快的解决方案,我相信您可以尝试其他解决方案
有人可以告诉我如何进行基于头部的转向吗?我知道如何在只移动相机时做到这一点,但我想通过头部和相机移动物体以跟随物体。 我需要这个,因为我想为对象实现游戏逻辑(如果我可以将相机视为普通对象,它对我也适用)。
我找到了这个仅用于转向相机的代码:
public float speed = /* some number */;
private CardboardHead head;
void Start()
{
head = // find the CardboardHead
// example:
// head = Camera.main.GetComponent<StereoController>().Head;
// or, make the variable public and use drag-and-drop in the Editor
}
void Update()
{
transform.position += speed * head.Gaze.direction;
}
我开始做游戏是为了团结,所以如果我有什么错误,请指正。
您是否在此处使用适用于 Unity 的 Cardboard 插件? https://developers.google.com/cardboard/unity/download
如果你这样做,那么有一个名为cardboard main的预制件,将它放在场景中,然后如果你看到其中有一个名为Head
的游戏object,它包含CardboardHead
脚本。所以这是你的脚本:
public GameObject head; // drag the Head gameobject to here or you can just get it from the start
void Start()
{
if (!head) // if you didn't drag the gameobject
{
head = FindObjectOfType<CardboardHead>().gameObject;
}
}
void Update()
{
transform.position += speed * head.transform.forward; // it is better to multiply by Time.deltaTime
}
另外,为什么它被标记为 Java?
新问题:
这就是我所做的。我拆分了 'visual' 和 'mechanic'。我从播放器中删除了网格渲染器,冻结了刚体的旋转。我为 'visual' 创建了一个新的 child 它有一个名为 Rotate.cs
的脚本并删除了它的碰撞器。
脚本更改:
在 Forward.cs
中使用 rb.AddForce(transform.forward * speed);
返回,在 Rotate.cs
中使用
void Update () {
transform.Rotate(Vector3.right * 5);
}
这是我能想到的最快的解决方案,我相信您可以尝试其他解决方案