Interaction Intermediate
Build on the fundamentals of VR by learning about multiple Interaction Managers, Interaction Layers, the Direct Interactor, Simple Interactable, and handling multiple Interactors.
We'll cover the following...
Since we now have a basic understanding of the Interaction System in Unity VR, we’ll discover the level of control the Unity XRI Toolkit gives us over such interactions.
Multiple Interaction Managers
Earlier, we discussed the role of the Interaction Manager as just a relay between Interactors and Interactables. Let’s see how we can leverage it to add depth to our game.
Let’s add another Grab Interactable to our game, the magic orb. This magic orb is created using a VFX graph. So, first, we have to install the Visual Effect Graph and Shader Graph from the package manager. You can use the package below to download the magic orb in your project:
Once the package is imported, the magic orb will be available as “GreenOrb” inside the “Package-export” folder in the “Project” window.
Note: If the magic orb VFX is not activated on drag and drop in the scene, click the “orb2” file in the “VFXGraphs” folder in project assets.
Make sure to add a Sphere Collider and XR Grab Interactable to the magic orb. Also, ensure that the “Is Trigger” property is unchecked. If we run the game now, we can grab the saber or orb with either hand or grab two sabers or orbs with both hands. The following animation demonstrates grabbing the saber with the right hand and the orb with the left:
Similarly, we can grab the orb with the right hand and the saber with the left hand.
However, we want the user to grab the saber in their right hand and the orb in their left. So, how do we do this? Yes, we’ll use another Interaction Manager!
Simply add another Interaction Manager to the scene as a secondary Interaction Manager. Assign this as the Interaction Manager attribute for the “XR Ray Interactor” script of the LeftHand Controller, the “XR Grab Interactable” script of the orb, and the “XR Socket Interactor” script of the podium.
Although this approach got the job done, it can quickly become troublesome when we wish to toggle this behavior at runtime. Some users would prefer wielding the saber in their left hand as opposed to the right hand. To implement such behavior, we’ll have to change the Interaction Manager attribute for Interactables and Interactors at runtime and sometimes even instantiate a new Interaction Manager. So, we’ll use Interaction Layers rather than different Interaction Managers.
Interaction Layers
...