- Home /
new input system with open xr/vr only returns digital/binary trigerr values
I starting development on a VR chess game. Currently, I'm trying to set up hand presence and controller input. I am using the new input system to achieve this. I am trying to get the float value of the second trigger button on the side of my touch 2 controllers. this button is known as the grip button. Here is an image of the button: https://imgur.com/ARh6Er5. Here is the important part of my code:
void Update()
{
float isPressed = controller.selectAction.action.ReadValue<float>();
}
this float isPressed should be smooth "analog" transition between 0 and 1 (0.1, 0.2, 0.3... 1) based on how far down the grip button is pressed. However, what happens is that it's always either 0 or 1 based on if the button is pressed or not and it behaves more like a bool.
I'm new to the new input system and I wasn't able to find the solution anywhere. I hope someone can help me out here. Thanks in advance.
Here is my whole script (most of it is not important for this problem):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
using TMPro;
public class TestActionInput : MonoBehaviour
{
private ActionBasedController controller;
//public TextMeshProUGUI text;
public TextMeshPro text;
// Start is called before the first frame update
public float isPressed;
void Start()
{
controller = GetComponent<ActionBasedController>();
controller.selectAction.action.performed += Action_performed;
}
private void Action_performed(UnityEngine.InputSystem.InputAction.CallbackContext obj) {
Debug.Log("Select Button is pressed");
}
// Update is called once per frame
void Update()
{
isPressed = controller.selectAction.action.ReadValue<float>();
text.text = "" + isPressed;
//Debug.Log(controller.selectAction.action.ReadValue<float>());
}
}
Answer by doleary-3800 · Feb 26, 2021 at 06:34 PM
Hi,
I think this video may help, It demonstrates how to change the grip trigger output to a float value instead of being a button press.
https://www.youtube.com/watch?v=qThlKMMHSpU&t=925s
Hope it helps.
It works! I tried changing it from triggerPressed to triggerButton before posting my question and nothing changed. Turns out I had to change it to just trigger, as you said! Sorry for the late response and thanks big time!
Thank you both! I was stuck on this for days. I get the value in a slightly different way using: InputActionReference.action.ReadValue();