Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Unity MR Part 5: Left and Right Controllers
Taikonauten profile imagetststs
tststs forTaikonauten

Posted on • Edited on • Originally published atMedium

     

Unity MR Part 5: Left and Right Controllers

👀 Stumbled here on accident? Start with theintroduction!

📚 This article will teach you how to set up the left and right controllers for the Meta Quest 3 in Unity. This setup is essential for enabling interaction with various elements within your Unity project, enhancing the user experience on the Meta Quest 3 platform.


ℹ️ If you find yourself facing any difficulties, remember that you can always refer to or download the code from our accompanyingGitHub repository


To keep the process straightforward, we'll use the starter assets from theXR Interaction Toolkit plugin. This approach simplifies the setup process, focusing on achieving a practical outcome quickly and efficiently.


Import XR Interaction Toolkit Starter Assets

We will utilize some of theXR Interaction Toolkit starter assets in this article. Go to thePackage Manager viaWindow → Package Manager and importStarter Assets which are located in the tabSamples as seen in the next screenshot.

You can locate the XR Interaction Toolkit in thePackage Manager by accessingUnity Registry and searching for 'interact'.

Importing Starter Assets for the XR Interaction Toolkit

Importing Starter Assets for the XR Interaction Toolkit

Enable the new Input System

ℹ️ The New Input System in Unity is a flexible and extensible system designed to replace the older input methods. It provides a more unified and consistent way to handle different input devices like keyboards, mice, gamepads, and touchscreens. This system allows for more customized and complex input configurations, making it easier to develop games and applications that can be controlled across various platforms and devices.

Go to yourProject Settings and enable the new input system. You’ll find it underActive Input Handling under the sectionPlayer and the tabOther Settings.

After selecting the new input system you will be asked to restart the Unity editor.

After restarting, the new input is now active. No additional steps required for now.


Adding the AR Input Manager

ℹ️ The AR Input Manager in Unity's AR Foundation is a component that manages input in AR applications. It serves as a central point for handling AR-specific input data, such as touch gestures, camera movement, and device orientation. This manager is essential for creating interactive and user-responsive AR experiences, as it efficiently processes and translates real-world user interactions into actions within the AR environment.

Select theSession GameObject in your hierarchy and add theAR Input Manager viaAdd Component.

Our Session GameObject with the added AR Input Manager

Our Session GameObject with the added AR Input Manager

The Input Action Manager

The Input Action Manager in Unity is a component that handles input actions within the New Input System. It allows developers to define and manage complex input actions like button presses, gestures, or movement inputs. This manager makes it easier to organize and respond to various user inputs in a structured and efficient manner, crucial for creating responsive and interactive gaming or application experiences.

ℹ️ For those interested in exploring the Input Manager in greater detail, additional information is available in the provided reference. This resource offers a comprehensive look into the functionalities and applications of the Input Manager, enhancing your understanding and proficiency in utilizing this component in your projects.Input System | Input System | 1.7.0.

Select theXR Origin (XR Rig) GameObject in your hierarchy.

Add XRI Default Input Actions to the list of Action Assets<br>

Add XRI Default Input Actions to the list of Action Assets

In the screenshot provided, you'll notice that we've addedXRI Default Input Actions to the list ofAction Assets. These assets were included as part of theStarter Assets from theXR Interaction Toolkit plugin, highlighting how the toolkit simplifies the integration of default input actions into your project.

If you're curious about the specific Input Actions included in the Action Asset, simply double-click on the selected action asset. This action will reveal the details and configurations of the Input Actions, providing a clear understanding of the functionalities they encompass.

XRI Default Input Actions in detail

XRI Default Input Actions in detail

Adding XR Input Modality Manager

TheXR Input Modality Manager in Unity dynamically switches between hands and controllers during runtime, depending on their tracking status.

  • if hands start being tracked, it switches to hand interactors.

  • if motion controllers are activated, it switches to controller interactors once they're tracked.

📚 This component is valuable even without hand tracking, as it deactivates controller GameObjects until they are tracked, preventing them from appearing by default.

Select theXR Origin (XR Rig) GameObject in your hierarchy and add theXR Input Modality Manager viaAdd Component. SelectLeft Controller andRight Controller as seen in the screenshot.

Selecting the left and right controller for the XR Input Modality Manager

Selecting the left and right controller for the XR Input Modality Manager

Choose a controller preset

For configuring the left and right controllers, we choose a controller preset imported through the starter assets. In your hierarchy select the GameObjectLeft Controller. To select a preset, click on the two sliders as depicted in the accompanying screenshot. This step is essential for customizing the controller settings in your project, ensuring they align with the imported presets for optimal functionality and user experience.

Open the preset window for the left controller

Open the preset window for the left controller

Selecting a preset for the left controller

Selecting a preset for the left controller

Similarly, for the Right Controller GameObject, follow the same process and select the corresponding preset for the right controller. This ensures that both controllers are appropriately configured with their respective presets, maintaining consistency and functionality in your setup.


Choose an Interaction Manager

For the final step in setting up our controllers, we need to assign the Interaction Manager to both the left and right controllers. As shown in the forthcoming screenshot, selectXR Interaction Manager as theInteraction Manager. This action links the controllers to the central system that manages interactions, ensuring they function correctly within the XR environment.

ℹ️Interaction Manager: The XR Interaction Manager that this interactor will communicate with.

Selecting the XR Interaction Manager as the Interaction Manager

Selecting the XR Interaction Manager as the Interaction Manager

Similarly, for the Right Controller GameObject, follow the same process and selectXR Interaction Manager as theInteraction Manager.


Testing the app

Run your Unity project viaBuild And Run as explained in the last article. You should now see the Unity project running in your headset as seen in the next screenshot. Move your Meta Quest 3 controllers to verify if everything is working as expected.

Testing the app if our controllers work

Testing the app if our controllers work

Next article

In our next article, we will delve into the aspect of detecting planes in MR environments. Plane detection is a cornerstone of MR, allowing virtual content to be realistically placed and interacted with in the physical world. We will explore how this technology works and the ways you can implement plane detection in your projects using Unity.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

More fromTaikonauten

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp