Question by
sHajir · Nov 22, 2016 at 07:01 PM ·
inputvrcontrollerfalse
SteamVR_Controller.GetPress , GetPressDown, GetPressUp always returns false !
using UnityEngine;
using System.Collections;
using Valve.VR;
public class WandController : MonoBehaviour {
private EVRButtonId triggerButton = EVRButtonId.k_EButton_SteamVR_Trigger;
public bool triggerButtonDown = false;
public bool triggerButtonUp = false;
public bool triggerButtonPressed = false;
private EVRButtonId gripButton = EVRButtonId.k_EButton_Grip;
public bool gripButtonDown = false;
public bool gripButtonUp = false;
public bool gripButtonPressed = false;
private SteamVR_Controller.Device controller { get { return SteamVR_Controller.Input((int) trackedObj.index); } }
private SteamVR_TrackedObject trackedObj;
void Start () {
trackedObj = GetComponent<SteamVR_TrackedObject>();
Debug.Log("trackedObj: "+trackedObj); //trackedObj is never null
}
// Update is called once per frame
void Update () {
if (controller == null)
{
Debug.Log("Controler Object ist null"); // controller object is never null
return;
}
gripButtonDown = controller.GetPressDown(gripButton); //is always false, also when pressing gripButton
gripButtonUp = controller.GetPressUp(gripButton);
gripButtonPressed = controller.GetPress(gripButton);
triggerButtonDown = controller.GetPressDown(triggerButton);
triggerButtonUp = controller.GetPressUp(triggerButton);
triggerButtonPressed = controller.GetPress(triggerButton);
Debug.Log("triggerButton: "+ controller.GetPress(triggerButton)); //is always false, also when pressing triggerButton
Debug.Log("triggerButtonDown: " + triggerButtonDown); //is always false, also when pressing triggerButton
//content of these if-statements never get activated/run -> also when pressing all Buttons permanently !
if (gripButtonDown)
{
Debug.Log("Grip Button was just pressed");
}
if (gripButtonUp)
{
Debug.Log("Grip Button was just unpressed");
}
if (triggerButtonDown)
{
Debug.Log("Trigger Button was just pressed");
}
if (triggerButtonUp)
{
Debug.Log("Trigger Button was just unpressed");
}
}
}
This script is attached to 'Controller (left)'.
Why do the methods 'controller.GetPressUp(gripButton); controller.GetPressDown(gripButton); controller.GetPressDown(triggerButton);' etc. always return false ; even though I'm pressing all the Buttons(Trigger, Grip, and all other buttons) on the Vive controller (left) ?
Thanks
Comment
Answer by Wiechering · Aug 04, 2017 at 01:52 PM
I now this is a very old Topic. Nevertheless i wanted to add a solution that (at least for me) works and ansers the question:
void Update () {
if ( Controller.GetPressDown (SteamVR_Controller.ButtonMask.Grip)) {
do_something();
}
if (Controller.GetPressUp (SteamVR_Controller.ButtonMask.Grip)) {
do_something_else();
}
}
Answer by RIDENTEM · Sep 16, 2018 at 03:28 PM
For anyone else who crosses this post and has the same problem I did, this solution did not work for me. Instead after poking around what finally worked for me was this:
public SteamVR_TrackedController controller;
void Start()
{
controller = GetComponent<SteamVR_TrackedController>();
}
void Update () {
if( controller.triggerPressed == true)
Debug.Log("A trigger has been pressed");
}