我们开始为HTC Vive创建一个应用程序,最初没有使用VRTK。最近,我们切换到使用VRTK,并遇到了一个问题,即当一个控制器握住触发器而另一个控制器按下另一个按钮时,我们想要执行一些操作。我们如何使用VRTK实现这一点?我们当前的代码:
controllerMain = SteamVR_Controller.Input((int)trackedObj.index);
controllerSecondary = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost));
// In Update()
if (controllerMain.GetPressDown(triggerButton) && controllerSecondary.GetPressDown(triggerButton))
{
scaleSelected(gameObj); //enlarges selected GameObject based on distance between controllers
}
if (controllerMain.GetPressDown(triggerButton) && controllerSecondary.GetPressDown(gripButton))
{
deleteObject(gameObj); //delete selected GameObject
}在VRTK文档中,我找不到任何使用两个控制器与同一对象进行交互的示例。在文档/示例中,一切都是基于事件的,而我们的代码不是,并且没有同时使用两个控制器的操作的示例。我们如何实现类似的行为?
编辑- VRTK
发布于 2017-02-07 21:40:46
当您与对象交互(使用抓取控制器)时,您知道哪个控制器正在进行抓取,因此您可以通过检查现有控制器的手,然后获取另一只手来找到另一个控制器,如下所示:
GameObject otherController;
if(VRTK_DeviceFinder.IsControllerLeftHand(grabbingObject)
{
otherController = VRTK_DeviceFinder.GetControllerRightHand();
}
else
{
otherController = VRTK_DeviceFinder.GetControllerLeftHand();
}它基本上检查当前抓取控制器,如果是左手,那么你想要右手(反之亦然)。
Bow和arrow示例脚本显示了这一点,它们可以在Examples目录中找到。
发布于 2017-02-07 17:27:47
只需使用布尔值保持每个触发器的状态:
bool triggerMainPressed;
bool triggerSecondaryPressed;
void Update()
{
if (controllerMain.GetPressDown(triggerButton))
{
triggerMainPressed = true;
}
if(controllerSecondary.GetPressDown(triggerButton))
{
triggerSecondaryPressed = true;
}
if (controllerMain.GetPressUp(triggerButton))
{
triggerMainPressed = false;
}
if(controllerSecondary.GetPressUp(triggerButton))
{
triggerSecondaryPressed = false;
}
if(triggerMainPressed && triggerSecondaryPressed)
{
scaleSelected(gameObj); //enlarges selected GameObject based on distance between controllers
}
else if(triggerMainPressed && controllerSecondary.GetPressDown(gripButton))
{
deleteObject(gameObj); //delete selected GameObject
}
}https://stackoverflow.com/questions/42085626
复制相似问题