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: Imgur: The magic of the Internet.
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>());
}
}