Motion Controller 的 Unity 和 Oculus Raycast 仅适用于 Guardian Border

Unity and Oculus Raycast from Motion Controller Only working at Guardian Border

我编写了一个简单的光线投射脚本,它附在 Oculus 运动控制器的手上。这个想法是 - 控制器就像一个真空吸尘器,它吸收名为 "Eosinophil2(Clone)".

的预制对象

在运动控制器之外的一些测试中,这有效。

我遇到的麻烦是当我将 Raycast 脚本放入运动控制器时。当我在 Guardian Border 旁边时,它似乎才按预期工作。

我已经打开和关闭边界,看看是否解决了任何问题,但没有。

我检查过光线投射线的方向是否正确 - 确实如此。

有什么想法吗?

 void FixedUpdate()
{
   // OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.RTouch);
    var up = transform.TransformDirection(Vector3.forward);
    //note the use of var as the type. This is because in c# you 
    // can have lamda functions which open up the use of untyped variables
    //these variables can only live INSIDE a function. 
    RaycastHit hit;
    Debug.DrawRay(transform.position, up * 20, Color.green,1);


    if (Physics.Raycast(transform.position, up, out hit, 20))
    {

        if (hit.collider.gameObject.name == "Eosinophil2(Clone)")
        {
            OVRInput.SetControllerVibration(.3f, 0.3f, OVRInput.Controller.RTouch);
            hit.collider.gameObject.transform.position = Vector3.MoveTowards(hit.collider.gameObject.transform.position, transform.position, 20 * Time.deltaTime);
        }

        else
        {
            //OVRInput.SetControllerVibration(0, 0, OVRInput.Controller.RTouch);
        }
    }
}


private void OnTriggerEnter(Collider other)
{
    if (other.gameObject.transform.name == "Eosinophil2(Clone)")
    {
        this.gameObject.GetComponent<AudioSource>().Play(0);
        Debug.Log("works");
        Destroy(other.gameObject);

        Debug.Log("HIT ONE!");
        hitRate++;
    }
}`enter code here`

故事的寓意 - 从头开始​​构建您的场景。

在上述构建场景中使用 OVRCameraRig 预制件。

使用 Oculus 的预建场景可能会损害健康、时间和代码。

我希望有一天这对某人有所帮助。