Question by
patchorang · Oct 15, 2016 at 09:47 PM ·
vrtriggerscontrollers
VR - Best method for keeping track of both controllers are interacting with an object.
I want the user to be able to resize objects by "grabbing" it with the trigger button of both controllers.
Here is my current code:
void OnTriggerStay(Collider other)
{
if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger))
{
int interactorCount = other.GetComponent<StateController>().controllerInteractionCount;
if (interactorCount == 0 || interactorCount == (int)trackedObj.index)
{
// Just this controller so move
other.GetComponent<StateController>().controllerInteractionCount = (int)trackedObj.index;
other.gameObject.transform.SetParent(this.gameObject.transform);
}
else
{
// Both controllers so scale
float scale = controllerManager.GetComponent<ControllerManager>().getDistance();
other.transform.localScale = new Vector3(scale, scale, scale);
}
}
if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger))
{
// No longer pulling trigger so reset
other.GetComponent<StateController>().controllerInteractionCount -= (int)trackedObj.index;
other.gameObject.transform.SetParent(null);
}
}
It has some bugs in it but it just feels like an inappropriate way to do this. Is there a better approach for doing something like this?
Comment
Your answer
Follow this Question
Related Questions
SteamVR Hand Slim is offset from real controller location, but only on the Valve Index. 1 Answer
My game becomes unresponsive when I use controllers (VR). 0 Answers
showing motion controller laser pointer 0 Answers
Need help with Vive controler 1 Answer
VR Challenge: Rotation issue when holding object with both hand controllers vertically 2 Answers