Skip to main content

Raycast Interactor

NAMESPACEMyDreamGameStudio.InteractAnything
MENU PATHInteraction System > Interactors > Raycast Interactor
COMPATIBILITYUnity 6.0+
DOC VERSION

Interacts with whatever the configured camera is looking directly at. This component casts a physics ray forward from the center of the camera each frame. It is the standard solution for first-person (FPS) or third-person (TPS) crosshair targeting systems.


Editor Interface​

RAYCAST INTERACTORCROSSHAIR RAYCASTFPS / TPSCasts forward from camera center for first-person / third-person crosshair targeting.CAMERA & RAYCAST SETUP✦ Auto-Wire CameraSource CameraNone (Camera)Ray Distance (m)3Interactable LayersEverything

Configuration​

Source Camera
CameraDef: Camera.main
The camera whose transform will drive the raycast. The ray fires directly along the camera's forward axis. Auto-wires to Camera.main during Awake() if left empty.
Ray Distance (m)
floatDef: 3.0
The maximum physical reach of the player. For standard first-person games, keeping this between 2.0 and 4.0 meters prevents players from interacting with objects through walls.
Interactable Layers
LayerMaskDef: Everything
Physics layer mask filtering which objects the ray can hit. It is highly recommended to restrict this to a dedicated 'Interactable' layer.

Target Resolution Pipeline​

The RaycastInteractor uses a robust resolution hierarchy to ensure complex prefabs register correctly while keeping continuous mechanics smooth.

  1. Direct Component Check: It first checks if the hit Collider has an Interactable attached directly to it.
  2. Root Fallback: If not, it checks GetComponentInParent<Interactable>(). This allows you to attach multiple specific colliders (like a door handle) to an object while keeping the logic on the root.
  3. Continuous Spatial Data: Even if the raycast hits nothing (or hits a non-interactable wall), the system still caches the exact point at the end of the Ray Distance. This ensures that if the player is currently operating a Drag or Push/Pull mechanic, spatial data continues to flow smoothly even if their crosshair slips off the object.