RaycastClosest
Function of: Workspace
Returns: Tuple <Dynamic, Vector3, Vector3>
Tags: instance
Given a ray, returns the closest intersected part within a max distance. Optionally ignores parts that are or are descendants of a specified dynamic. Returns in order: hit dynamic, ray hit position, and the normal of the surface hit
Parameters
Name | Type | Description |
---|---|---|
ray | Ray | The ray to cast with |
ignoreAndDescendants | Dynamic | The optional dynamic to ignore parts if equal to or children of |
maxDistance | Number | The max distance in meters the ray will travel |
onlyCollidable | Boolean |
Example
-- prints the name of a part when the local player clicks on something local player = Players.LocalPlayer local mouse = player.Mouse mouse.LeftButtonDown:connect(function() local ray = Ray.new(mouse.origin.p, mouse.origin.lookvector) local hit = Workspace:RaycastClosest(ray, player, 100) if hit then print('clicked on ' .. hit.name) end end)