用Vive控制器不能拾取球体。(Can't pickup sphere with Vive controller. Collision not detected)

编程入门 行业动态 更新时间:2024-10-23 19:23:50
用Vive控制器不能拾取球体。(Can't pickup sphere with Vive controller. Collision not detected)

我正在从VR Dev School做一个教程。 课程是拾取对象和父变换。 这是我从课程中完全复制的代码。 我有脚本和球形对撞机连接到控制器(左)。 我试过打开/关闭“触发器”。 控制台中未检测到冲突。 我没有收到任何错误或警告。

任何帮助表示赞赏,我会回答任何问题

using UnityEngine; using System.Collections; [RequireComponent(typeof(SteamVR_TrackedObject))] public class PickupParent : MonoBehaviour { SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device; void Awake () { trackedObj = GetComponent<SteamVR_TrackedObject>(); } void FixedUpdate () { device = SteamVR_Controller.Input((int)trackedObj.index); if(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated touchdown on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press down on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press Up on the trigger"); } } void onTriggerStay(Collider col) { Debug.Log("You have collided with " + col.name + " and activated onTriggerStay"); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You have collided with " + col.name + " while holding down Touch"); col.attachedRigidbody.isKinematic = true; col.gameObject.transform.SetParent(gameObject.transform); } } }

I am doing a tutorial from VR Dev School. The lesson is Picking Up an Object and Parent the Transform. This is the code I copied exactly from the lesson. I have the script and a sphere collider attached to controlller(left). I've tried toggling 'is trigger' on/off. The collision is not being detected in the console. I am not receiving any errors or warnings.

Any assistance is appreciated and I will answer any questions

using UnityEngine; using System.Collections; [RequireComponent(typeof(SteamVR_TrackedObject))] public class PickupParent : MonoBehaviour { SteamVR_TrackedObject trackedObj; SteamVR_Controller.Device device; void Awake () { trackedObj = GetComponent<SteamVR_TrackedObject>(); } void FixedUpdate () { device = SteamVR_Controller.Input((int)trackedObj.index); if(device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated touchdown on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press down on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated press Up on the trigger"); } } void onTriggerStay(Collider col) { Debug.Log("You have collided with " + col.name + " and activated onTriggerStay"); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You have collided with " + col.name + " while holding down Touch"); col.attachedRigidbody.isKinematic = true; col.gameObject.transform.SetParent(gameObject.transform); } } }

最满意答案

这是一个简单的错误。 它应该是OnTriggerStay而不是onTriggerStay 。 请大写O并检测触发/碰撞。

This is a simple mistake. It should be OnTriggerStay not onTriggerStay. Please capitalize the O and trigger/collision should be detected.

更多推荐

本文发布于:2023-07-22 12:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219942.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:球体   控制器   pickup   Vive   Collision

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!