Motion Controller中的Unity和Oculus Raycast仅在Guardian Border工作

时间:2018-08-09 14:42:27

标签: unity3d raycasting oculus

我已经编写了一个简单的光线投射脚本,该脚本附加在Oculus Motion Controller的手上。这个想法是-控制器的作用就像真空一样,它吸取了名为“ Eosinophil2(Clone)”的预制对象。

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

我遇到的麻烦是当我将Raycast脚本放入运动控制器中时。仅当我在“监护人边境”旁边时,它才能按预期工作。

我已经打开和关闭边框,看能不能解决任何问题,但不能解决问题。

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

有什么想法吗?

 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`

1 个答案:

答案 0 :(得分:0)

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

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

使用来自Oculus的预构建场景可能对健康,时间和代码有害。

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

相关问题