离谱!怎么有两个raycast方向 -- Unity for VR Controller Raycasting

    public GameObject leftController;
    public GameObject rightController;

	
    public void OnOptionSelected(InputAction.CallbackContext context)
    {
        if (InteractionController.Instance.currentModeName != "SideBySideMode") { return; }

        if (context.action.name == "SelectOption")
        {
            if (context.performed)
            {
                GameObject controller = rightController;
                Ray ray = new Ray(controller.transform.position, controller.transform.forward);
                RaycastHit hit;
                int targetLayerMask = 1 << LayerMask.NameToLayer("SideBySideClickable");

                if (Physics.Raycast(ray, out hit, Mathf.Infinity, targetLayerMask))
                {
                    Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 10f);

                    if (hit.collider != null)
                    {
						//logic
                    }
                }
                else
                {
                    Debug.DrawRay(ray.origin, ray.direction * 1000, Color.red, 10f)

                    Debug.Log("No hit in side by side mode");
                }
            }
        }
    }

上面的代码得到的raycast是下图红线,而实际上我的controllor指着的是绿线的方向。我凌乱了,怎么得到的raycast不一样。
在这里插入图片描述
找到的原因是我的hirarchy view里面,应该把RightController和LeftController拖进去,而我一开始拖动的是XRControllerRight和XRControllerLeft,因此会有上面的问题。

更深层的原因就是因为XRControllerRight和RightController的transform不一样。如果后面再出现这种问题,就需要检查一下设备有没有找对。

在这里插入图片描述

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-04-29 16:54:01       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-04-29 16:54:01       106 阅读
  3. 在Django里面运行非项目文件

    2024-04-29 16:54:01       87 阅读
  4. Python语言-面向对象

    2024-04-29 16:54:01       96 阅读

热门阅读

  1. 【AI大模型】Prompt Engineering 基础知识与挑战

    2024-04-29 16:54:01       35 阅读
  2. 【Spring AI】03. 图像生成 API

    2024-04-29 16:54:01       31 阅读
  3. git版本控制基础工作流

    2024-04-29 16:54:01       31 阅读
  4. k8s的PV/PVC详解以及使用范例

    2024-04-29 16:54:01       29 阅读
  5. Android面试

    2024-04-29 16:54:01       32 阅读
  6. 从零开始搭建SpringCloud

    2024-04-29 16:54:01       32 阅读
  7. react怎么只让接口请求一次

    2024-04-29 16:54:01       31 阅读
  8. P9586 「MXOI Round 2」游戏

    2024-04-29 16:54:01       32 阅读
  9. vue 快速入门 系列 —— 玩转 CMS

    2024-04-29 16:54:01       26 阅读
  10. 【校招VIP】985 211求职策略

    2024-04-29 16:54:01       29 阅读
  11. 【设计模式】12、observer 观察者模式

    2024-04-29 16:54:01       30 阅读