I am making a VR game where the player drives a car. To use the pedals, I intend to map the gas and brake to the triggers on the Vive controllers, however I do not know how to detect how far a trigger has been pulled.
As an example of what I want, play almost any game that lets you drive a car using an Xbox controller, and only pull the trigger halfway. In most games, this would keep you moving at half your top speed. I want to do this with the Vive triggers, but can’t find a reference to the trigger’s axis. Please help.
@chris1012 This is the reference you are looking for
You can use the UnityEngine.Input class to access the axis and button values.
- Left Controller Trigger (7) (Squeeze) ------ Unity Axis ID 9
- Right Controller Trigger (7) (Squeeze) ---- Unity Axis ID 10
Create Inputs for Gas and Brake buttons.
Example Input Manager Script
using UnityEngine;
public class InputManager : MonoBehaviour {
void Update()
{
// - Universal Unity Input for Unity Axis ID 9 and 10
// Gas - 9th axis joystick
// Brake - 10th axis joystick
if (Input.GetAxis("Gas") != 0)
{
// Show the analog trigger values for Gas Trigger Button
Debug.Log("Analog Gas Button Axis Value: " + Input.GetAxis("Gas"));
}
if(Input.GetAxis("Brake") != 0)
{
// Show the analog trigger values for Brake Trigger Button
Debug.Log("Analog Brake Button Axis Value: " + Input.GetAxis("Brake"));
}
}
}
-
-
You can also use SteamVR_Controller.Device to get axis and button values*
public SteamVR_TrackedObject mTrackeObject = null; public SteamVR_Controller.Device mDevice; private void Awake() { mTrackeObject = GetComponent<SteamVR_TrackedObject>(); } void Update () { mDevice = SteamVR_Controller.Input((int)mTrackeObject.index); Vector2 axisValue = mDevice.GetAxis(SteamVR_Controller.ButtonMask.Trigger); }