Direct Interaction
This interaction is used to detect when an object is touched by another. The most common case is when an object is touched with the controller or hand tracking, but it's also used to detect collisions with other objects.
The Direct interaction consists of:
- Near-Far Interactor: Near-Far Interactor is the interactor which performs this kind of interaction. This component is provided by Unity´s XR Interaction Toolkit. By default VIROO provides already configured Near-Far Interactors attached to the controllers and hands.
- XR Simple Interactable: XRSimpleInteractable is the component with which Near-Far Interactor interacts.
- Viroo XR Simple Interactable: this component is in charge of configuring the way XRSimpleInteractable interacts with the interactors and also that the interaction events are triggered by networking.
Add a Direct Interaction to a GameObject
To add direct interaction to an object you must:
- Set up the Interactable Object with the necessary components.
- Configure the events you want to handle.
Set up the Interactable object
To make an object respond to a Direct interaction it must have, at least, the following components.
- XR Simple Interactable: Unity´s XR Interaction Toolkit component.
- Collider: this GameObject or its children must have one or more colliders.
- Network Object: necessary to identify the GameObject by Networking.
- Viroo XR Simple Interactable: necessary to setup how XR Simple Interactable is interacted and to launch the events through the Network.
XR Simple Interactable
This is a Unity´s XR Interaction Toolkit component and is the simplest version of an Interactable object. It's intended to be used as a way to respond to interaction events with no underlying interaction behavior. For more information please refer to the official documentation here.
Important
The XRSimpleInteractable component must be in the Default
layer.
Collider
For Near-Far Interactor to interact with Simple Interactable, it's necessary that there is at least one collider, which can be at the same level of the component or in one of its children. The collider can be of type Trigger or not, but if it's of type Trigger, it must be dragged in the Colliders field of the XR Simple Interactable component, it won't register it automatically as it does with the non-trigger colliders.
Network Object
For network functions to work properly, interacting components need this component that uniquely identifies them across the network. It's therefore important to ensure that their ObjectId identifier isn't repeated.
Viroo XR Simple Interactable
This VIROO component is necessary to setup how XR Simple Interactable is interacted and to launch the events through the Network.
The XR Simple Interactable component by default doesn't differentiate if it's being interacted by a XR Direct Interactor, XR Ray Interactor or a XR Gaze Interactor, that's why VIROO, through this component, provides a way to limit the way in which it interacts with this interactable in order to configure it so that it can only be interacted by an interactor of one type and not by both.
Field | Description |
---|---|
Send Network Events | If this box is checked the events triggered by the XRSimpleInteractable (HoverEnter, Activate…) will be networked, otherwise the events will be triggered only locally. |
Allow Direct Interaction | If this checkbox is checked it means that the associated interactable will interact with a Near-Far Interactor closely or XR Direct Interactor. |
Interact With Hands | In this field you can specify whether the interactable is hand-interactable. It has four possible values, None, Left, Right, Both. Allow Direct Interaction must be checked. |
Tag Filters | If you want the interactable to interact only with specific DirectInteractors, you can define tags for this purpose. For more information check the Custom Direct Interactors section in this page. Allow Direct Interaction must be checked. |
Allow Ray Interaction | If this checkbox is checked it means that the associated interactable will interact with a Near-Far Interactor remotely and XR Gaze Interactor. |
Allow Distance Select Interactor | Check this checkbox to allow interactable be selected remotely through a Near-Far Interactor. It's commonly used to be able to grab objects from a distance. |
Normally the standard configuration when we want to have a Direct Interaction is to have Allow Direct Interaction
enabled and Allow Ray Interaction
disabled.
Custom Direct Interaction
If instead of interacting with controls or hands, we want a specific object to interact with a Simple Interactable, we must define our own custom DirectInteraction. To do this we will do the following:
Setting up the Interactor
- Create new GameObject.
- Add a Collider and make it trigger type. Adjust the size to fit your needs.
- Add a Rigidbody and to prevent it from falling: deactivate gravity and make it kinematic.
- Add XR Direct Interactor component to the GameObject.
- Add Viroo XR Direct Interactor component. Fill the TagFilter field with an identifying string.
Viroo XR Direct Interactor | |
---|---|
Field | Description |
Tag Filter | The text label with which this Interactor is identified. |
Setting up the Interactable
- Create new GameObject.
- Add a Collider and make it trigger if you need it to be. Adjust the size to fit your needs.
- Add XR Simple Interactable component. In the
InteractableEvents
section locate theHoverEntered
event and drag into it what you want to be done when the interaction occurs. - Add a Viroo XR Simple Interactable and in the
Interaction Settings
section selectNone
in theInteract With Hands
section. In theTag Filters
field add a new entry and type the same string you put in theTagFilter
of the Viroo XR Direct Interactor field. Finally, disable the Allow Ray Interaction field.
Configuring the Events
At this point you can use XRSimpleInteractable events to trigger logic when direct interaction happens. VIROO Interaction System ensures that XRSimpleInteractable events are propagated over the network to all users if Send Network Events
is selected. With this, the events you subscribe will be called to all users in the VIROO Application.
If you want to use the VIROO Interaction System Actions and you are sending events through the network, you must use the LocalExecute functions (instead of Execute).
In the following example a Move Action is triggered when the object is interacted by ray.
Here are the most common events that are used when performing Direct Interaction.
Event | Description |
---|---|
Hover Entered | The event that's called when an Interactor begins hovering over this Interactable. |
Hover Exited | The event that's called when an Interactor ends hovering over this Interactable. |
A complete list of all events is available here