Raycast Interactions
The HoloMIT SDK’s raycast interaction module allows users to point and select objects at a distance using a visual ray and pointer. It provides hover events and fires actions with ButtonX, based on tag-filtered raycasts.
Overview
- Draws a ray from the controller to visualize potential interactable targets.
- Detects hover enter/exit based on the
selectableTag
and firesHoverEnterEvent
/HoverExitEvent
. - Fires a selection event when ButtonX is pressed on a hit collider with a
NetworkTrigger
.
Requirements
- Unity 2022.3 LTS or later
- New Input System (for reading LeftTrigger, LeftGrip, ButtonX)
- XR Interaction Toolkit (for controller tracking)
- HoloMIT Core & EventManager (for
NetworkTrigger
and hover events) - InteractionRaycast prefab placed under your player rig
- Project tags defined:
- Selectable for objects that can be pointed at
- ObjectDragger for draggable objects (if used)
Setup
- Place InteractionController
- Add the InteractionRaycast component to your player.
- Configure the Component
- On the
InteractionController
component, assign:- lineSelectableMat / lineNotSelectableMat for valid/invalid targets
- References to LineRenderer and targetMarker for visuals
- leftHand and rightHand transforms (if not auto-detected)
- selectableTag (default: “Selectable”) and dragTag (default: “ObjectDragger”)
- maxDistance and raycastLayers to define range and layers
- On the
- Enable Input Actions
InteractionController
uses the HoloMITControls asset for trigger and ButtonX bindings.
- Test Tags and Layers
- Tag your interactable GameObjects accordingly
- Verify that the ray and marker appear when pointing
Exposed Parameters
Property | Type | Description |
---|---|---|
lineSelectableMat | Material | Material when the ray hits a selectable object. |
lineNotSelectableMat | Material | Material when the ray does not hit a selectable object. |
lineRenderer | LineRenderer | Component that draws the ray. |
targetMarker | GameObject | Visual indicator at the hit point. |
leftHand | Transform | Origin transform for left-hand raycasts. |
rightHand | Transform | Optional origin for right-hand raycasts. |
selectableTag | string | Tag for hover/select detection (default: Selectable). |
dragTag | string | Tag for draggable objects (default: ObjectDragger). |
maxDistance | float | Maximum raycast distance (default: 20). |
raycastLayers | LayerMask | Layers considered for raycast collisions. |
Usage
- Activate Ray: Hold the left trigger (while not gripping) to enable the ray and marker.
- Hover: Move the ray over objects tagged Selectable; hover events fire automatically.
- Select: Press ButtonX while pointing at a valid object; its
NetworkTrigger
will fire. - Cleanup: Release the trigger to hide the ray and marker.
Known Limitations
- Configured only for the left hand by default; extend to both hands if needed.
- No smoothing transitions; the ray appears/disappears instantly.
- Relies on Unity physics and tags; ensure accurate collider and tag setup.
- Does not support drag operations out of the box; additional logic required.