unity-webxr-export icon indicating copy to clipboard operation
unity-webxr-export copied to clipboard

Trigger and Grip button on Oculus did not working

Open AmalinTasnim opened this issue 1 year ago • 8 comments
trafficstars

Describe the bug Trigger and Grip button not function when hover to object to interact.

To Reproduce Steps to reproduce the behavior:

  1. Create a new Unity Project 2022.3.12f1.
  2. Switch platform to WebGL.
  3. Import WebXR Export and WebXR Interaction Toolkit sample packages from OpenUPM.
  4. Enter XR mode in headset.
  5. Use oculus to interact with 3D Model (rotate the 3D model) but it is not function. Only can move forward and backward and can turn around.

Expected behavior I expect that can use both left and right controller to interact with 3D model in my project.

Screenshots Screenshot 2024-04-04 101551 Screenshot 2024-04-04 101622 Screenshot 2024-04-04 101644

I want to when user play this project, user can interact with this 3d model(can rotate the model using controller in VR Mode). I already attached box collider and model rotation script. When using pc/laptop its working but not working in VR. Screenshot 2024-04-04 102048

Unity info (please complete the following information):

  • Editor version: Unity 2022.3.12f1
  • WebXR package version: 0.22.0
  • WebXR Interactions version: 0.22.0
  • Git or OpenUPM: OpenUPM
  • Using old components (like the Desert sample) or Input System + XR Interaction Toolkit: Input System + XR Interaction Toolkit
  • Built-in render pipeline or URP: URP

Desktop (please complete the following information):

  • OS + Version: Windows 11
  • Browser: Chrome 123

Headset (please complete the following information):

  • Device: Meta Quest 2
  • OS: [e.g. Meta Quest build 55.0]
  • Browser:Meta Quest Browser

Smartphone (please complete the following information):

  • Device: Any
  • OS: Any
  • Browser: Any

Additional context This is the script for model rotation:

using System.Collections.Generic; // Added namespace for List<> using UnityEngine; using UnityEngine.XR;

public class ModelRotation : MonoBehaviour { private bool isRotating = false; private Vector3 lastTouchPosition;

private InputDevice inputDevice; // Reference to the input device

void Start()
{
    // Try to find the input device associated with the right hand
    List<InputDevice> inputDevices = new List<InputDevice>(); // Initialize List<InputDevice>
    InputDevices.GetDevicesAtXRNode(XRNode.RightHand, inputDevices); // Pass inputDevices to GetDevicesAtXRNode
    if (inputDevices.Count > 0)
    {
        inputDevice = inputDevices[0]; // Assign the first input device found to inputDevice
    }
}

void Update()
{
    // Check for mouse input
    if (Input.GetMouseButtonDown(2)) // Check if middle mouse button is pressed
    {
        StartRotation(Input.mousePosition);
    }
    else if (Input.GetMouseButtonUp(2)) // Check if middle mouse button is released
    {
        StopRotation();
    }

    // Check for touch input
    if (Input.touchCount > 0)
    {
        Touch touch = Input.GetTouch(0); // Get the first touch

        if (touch.phase == TouchPhase.Began)
        {
            StartRotation(touch.position);
        }
        else if (touch.phase == TouchPhase.Ended)
        {
            StopRotation();
        }
    }

    // Check for XR controller input
    if (inputDevice.isValid)
    {
        // Check for trigger button press on the controller
        if (inputDevice.TryGetFeatureValue(CommonUsages.triggerButton, out bool triggerPressed) && triggerPressed)
        {
            StartRotation(Vector3.zero); // You can pass any arbitrary vector here as position
        }
        else
        {
            StopRotation();
        }
    }

    if (isRotating)
    {
        // Calculate the rotation amount based on the difference in touch position
        Vector3 deltaTouchPosition = Input.mousePosition - lastTouchPosition;
        float rotationSpeed = 0.5f;

        // Set the rotation only around the Z-axis
        Vector3 rotation = new Vector3(0, 0, -deltaTouchPosition.x) * rotationSpeed;

        // Rotate the model around its local Z-axis
        transform.Rotate(rotation, Space.Self);

        // Update the last touch position for the next frame
        lastTouchPosition = Input.mousePosition;
    }
}

// Start rotation function
private void StartRotation(Vector3 position)
{
    RaycastHit hit;
    Ray ray = Camera.main.ScreenPointToRay(position);

    if (Physics.Raycast(ray, out hit))
    {
        if (hit.collider == GetComponent<Collider>()) // Check if the collider hit is the collider of the model
        {
            isRotating = true;
            lastTouchPosition = position;
        }
    }
}

// Stop rotation function
private void StopRotation()
{
    isRotating = false;
}

}

AmalinTasnim avatar Apr 04 '24 02:04 AmalinTasnim

You are trying to use the old input manager to get device features, instead you need to use the new input system.

inputDevice.TryGetFeatureValue is not part of the new input system.

https://docs.unity3d.com/Packages/[email protected]/manual/QuickStartGuide.html You can look at the sample code there, and see that there's a using UnityEngine.InputSystem.

De-Panther avatar Apr 04 '24 02:04 De-Panther

There is not "input action" in my input system package Screenshot 2024-04-04 104945

AmalinTasnim avatar Apr 04 '24 02:04 AmalinTasnim

You can look at the WebXR XR Interaction Toolkit sample scene to see how the components there listening to controller input. It's not related to WebXR, it's related to the Input System. Look for tutorials on how to use XR controllers with the new input system.

De-Panther avatar Apr 04 '24 02:04 De-Panther

Did you manage to solve the issue?

De-Panther avatar Apr 09 '24 13:04 De-Panther

What can i use instead of XR Grab Interactable script to interact with the 3D model, to rotate them?

AmalinTasnim avatar Apr 16 '24 03:04 AmalinTasnim

It's up to you... From your screenshots you have all the setups you need for using XR Controller input with the new input system. You have both the XR Interaction Toolkit sample and the WebXR XR Interaction Toolkit sample and they both have grabbing object interaction in them.

And you can look in Unity's manual or in the source of those samples how to use InputActionProperty and InputAction.ReadValue. Those are all standard Unity Input System, and not specific for WebXR... https://docs.unity3d.com/Packages/[email protected]/manual/RespondingToActions.html

De-Panther avatar Apr 16 '24 04:04 De-Panther

Hi, is it possible if we hide the option for AR and VR button when play on PC web browser but it will only appear when using oculus browser? image

AmalinTasnim avatar Apr 24 '24 02:04 AmalinTasnim

Was the Trigger/Grip issue was solved?

Regarding the buttons, you'll have to create your own WebGLTemplate, and write custom HTML/JavaScript code. I'll recommend on hiding the buttons when they are not active, rather than specifically displaying them on Quest Browser, as users on other headsets, or even on newer Quest browsers might not be able to play.

De-Panther avatar May 17 '24 23:05 De-Panther