Player Raycasting: The Eyes of Interaction

How we're implementing robust raycasting for player interaction -- from object detection to UI crosshair synchronization. The foundation of every interaction in Our Open World.

Raycast-Based Interaction Controller

PURPOSE: Performs raycasts from the camera and detects IInteractable objects. Acts as the bridge between player input and interactable objects. Synchronizes with UI Toolkit for interaction prompts.

ARCHITECTURE: - Uses Physics.Raycast from camera center - Detects IInteractable implementations - Fires events for UI updates (InteractionEvents) - Decoupled: Knows nothing about specific interactables

PERFORMANCE: - Raycasts performed only on input or timer - Layer mask filtering for efficiency - Cached camera reference

UI INTEGRATION: This system fires InteractionEvents.HoverEnter/Exit/Interact which are consumed by InteractionPromptUI (built with Unity UI Toolkit). The UI component is available in UnityUIBuilder: library/interaction-prompt

EXAMPLE SETUP: // Attach to Player prefab (usually on camera or separate script holder) var raycastSystem = GetComponent<RaycastInteractionSystem>(); raycastSystem.Settings.maxDistance = 5f; raycastSystem.Settings.interactionLayer = LayerMask.GetMask("Interactable");

Example 1

// Attach to Player prefab (usually on camera or separate script holder)
var raycastSystem = GetComponent<RaycastInteractionSystem>();
raycastSystem.Settings.maxDistance = 5f;
raycastSystem.Settings.interactionLayer = LayerMask.GetMask("Interactable");

⚙️ Technical Details

Namespace: OurOpenWorld.Systems.Interaction
Dependencies: IInteractable, InteractionEvents, Unity.InputSystem
Related: IInteractable, InteractionPromptUI, CrosshairController
raycastinteractionplayer-controllerui-sync