Virtual and Augmented Reality together are now referred to as XR or “Extended-Reality”.
You’re in the right place at the right time to build something amazing in XR!
XR applications can be created in Unity for many devices, our focus will be on Microsoft Hololens 2 and the Meta Quest
In this blog post series we will focus on Meta Quest!
Check out other blog articles in this (and other) series!
Quick links to Lance’s latest XR Step-by-Step blog articles by device
We have our controllers ready to go! If not, see the previous blog article in this series. Let’s start grabbing and throwing things around 🙂
Full Step-by-Step Instructions!
Goals…
- What is an Interactor? What is an Interactable?
- Add Interactors to Controllers
- Create Interactables
Download the finished code for this blog article @ Github Repo
What is an Interactor? What is an Interactable?
- Interactor: Very simply, an Interactor is the thing performing an interaction in the virtual world, like your controller or your virtual hand.
- Interactable: An Interactable is what the Interactor interacts with. Like a ball or a button that can be pushed, thrown, or otherwise interacted with.
Add Interactors to Controllers
- XR Interaction Toolkit as it’s core was created to make it easy for XR developers to make rich experiences, and at the heart of those experiences is enabling the user to interact with their virtual environment.
- We will be adding close grabbing interactor ability to our right controller, and enabling far away grabbing interactor ability in our left controller (think tractor beam from Star Wars).
- We will start by removing the default line interactors from the Right controller
- (Hierarchy) Expand XR Origin (XR Rig) -> Click Right Controller
- (Inspector) Within XR Ray Interactor -> Click the vertical “…” icon
- Click Remove Component
- (Inspector) Within XR Interactor Line Visual -> Click the vertical “…” icon
- Click Remove Component
- (Inspector) Within Line Renderer -> Click the vertical “…” icon
- Click Remove Component
- Ok, we removed what we needed to – now let’s make the Right controller into a Grab Interactor.
- We need to add the XR Direct Interactor and a Sphere Collider.
- The Sphere Collider sets a spherical area within which objects can be grabbed, it’s too big by default – so we’ll make it smaller. Think of it as a sphere around your hand, if the object is within that area you can interact with it.
- (Hierarchy) Click Add Component
- (Add Component Search) Type XR Direct
- Click XR Direct Interact
- (Hierarchy) Click Add Component
- (Add Component Search) Type Sphere
- Click Sphere Collider
Create Interactables
- We’ll create a “table” on which we’ll place objects.
- (Hierarchy) Right-Click
- Click 3D Objects
- Click Cube -> Rename it Table
- (Hierarchy) Click Table
- (Inspector) Change the Transform values (in image below)
- (Project) Click Materials folder
- Drag Blue onto the Table cube
- Note, if you didn’t create a Blue before when we were coloring the controller – refer back to that article on how to create a Material
- (Hierarchy) Right-Click
- Click XR
- Click Grab Interactable -> Rename it Grab Cube
- (Hierarchy) Click Grab Cube
- (Inspector) Change Transform values
- (Inspector) Expand XR Grab Interactable
- Click Movement Type
- Click Velocity Tracking
- There are a couple different Movement Type choices, but Velocity Tracking is generally the best choice – but feel free to make several cubes and try them all 🙂
- Build and Run
- Awesome! If you put your Right controller close to the cube and click the Grab button (NOT the Trigger button) you grab the cube!
- If you release the Grab button, it drops.
- If you aim the laser from your Left controller at the cube and click the Grab button, it tractor beams to your hand!!
- If you grab the cube and make a throwing motion and release the Grab button you Yeet it! 🙂
I always love feedback and suggestions for new XR / AI blog posts!
Go build something amazing in XR & AI! — Lance 🙂
Check out other blog articles in this (and other) series!
Quick links to Lance’s latest XR Step-by-Step blog articles by device
2 thoughts on “XR Step-by-Step 2023! Meta Quest: Grab, Tractor Beam and Yeeting! Unity 2022 + Open XR + XR Interaction Toolkit”