Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigger and Grip button on Oculus did not working #371

Open
AmalinTasnim opened this issue Apr 4, 2024 · 8 comments
Open

Trigger and Grip button on Oculus did not working #371

AmalinTasnim opened this issue Apr 4, 2024 · 8 comments

Comments

@AmalinTasnim
Copy link

AmalinTasnim commented Apr 4, 2024

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;
}

}

@De-Panther
Copy link
Owner

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/com.unity.inputsystem@1.8/manual/QuickStartGuide.html
You can look at the sample code there, and see that there's a using UnityEngine.InputSystem.

@AmalinTasnim
Copy link
Author

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

@De-Panther
Copy link
Owner

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
Copy link
Owner

Did you manage to solve the issue?

@AmalinTasnim
Copy link
Author

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

@De-Panther
Copy link
Owner

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/com.unity.inputsystem@1.8/manual/RespondingToActions.html

@AmalinTasnim
Copy link
Author

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

@De-Panther
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants