Using trigger axis from VR Vive controller

Hi.

I’m trying to create a script that will move an object (trigger) between 2 local positions: 0,0,0 and 0,0,(0.01f), but I can only get access to VR Vive controller trigger as if it was a button:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class FN_Trigger : MonoBehaviour
{
  private SteamVR_TrackedObject trackedObject;
  private SteamVR_Controller.Device device;

  // Use this for initialization
  void Start()
  {
  GameObject RController = GameObject.Find("Controller (right)");
  trackedObject = RController.GetComponent<SteamVR_TrackedObject>();
  device = SteamVR_Controller.Input((int)trackedObject.index);
  transform.localPosition = new Vector3(0, 0, 0);
  }

  // Update is called once per frame
  void Update()
  {
  if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger))
  {
  device.TriggerHapticPulse(10000);
  transform.localPosition = new Vector3(0, 0, 0.01f);
  }
  if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger))
  {
  transform.localPosition = new Vector3(0, 0, 0);
  }
  }

}

How can I access its axis reading and use it to move my object over with it?

GetAxis from what I remember. I haven’t used steamvr directly in a long time though. I modified VRTK’s controller events to get all the data I want.

Thanks for an idea @WarmedxMints_1 , but with GetAxis I can only get access to touchpad x and y-axis using:

device.GetAxis().x
devise.GetAxis().y

I thought that trigger would be the z-axis, but it only allows x and y.

Does anyone have an example that uses trigger axis?

I seem to recall it is

SteamVR_Controller.Input(index).GetAxis(buttonId)

with Index being an int which the controller is assigned to an buttonID being

EVRButtonId.k_EButton_SteamVR_Trigger
1 Like

Ok, I got the axis reading with:

GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x

And I got it to move the trigger with:

transform.localPosition = new Vector3(0, 0, device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x * 0.01f);

Thank you very much!