We started creating an app for HTC Vive without using VRTK initially. Recently we switched over to using VRTK and ran into a problem where we want to do some actions when one controller is holding the trigger and the other is pressing another button. How do we achieve this using VRTK? Our current code:
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
}
I couldn't find any examples where both controllers are used to interact with the same object in the VRTK docs. In the docs/examples, everything is event based while our code is not and there are no examples of actions with both controllers. How do we achieve similar behavior?
EDIT- VRTK
When you're interacting with the object (with the grabbing controller) you know which controller is doing the grabbing, therefore you can find out the other controller by checking the hand of the existing controller and then getting the other hand, like so:
GameObject otherController;
if(VRTK_DeviceFinder.IsControllerLeftHand(grabbingObject)
{
otherController = VRTK_DeviceFinder.GetControllerRightHand();
}
else
{
otherController = VRTK_DeviceFinder.GetControllerLeftHand();
}
Which basically does a check on the current grabbing controller and if it's the left hand then you want the right hand (and vice versa).
The Bow and arrow example scripts show this they can be found in the Examples directory.