Raycast

A test that traces a straight line through the world and reports the first part it meets.

Think of it as A laser pointer.

workspace:Raycast(origin, direction, params) returns a RaycastResult for the first hit, or nil. The direction vector's length is the range. RaycastParams can include or exclude a list of instances, so a ray can be told to see only enemies, or everything except the player.

Where the picture breaks

It reports only the first hit, and filters make whole groups of parts invisible to it, so it can pass through walls or stop on the wrong thing.

Raycast tests one segment against the parts its RaycastParams allow and returns the nearest intersection or nil. Include lists see only listed parts; Exclude lists see everything else. To respect cover, the ray must be able to see the cover.

See it with the rest of the analogy cast

Official reference: create.roblox.com

Related terms