Raycasting

Wikipedia: Raycasting

Raycasting is the use of intersection tests to solve problems in ROBLOX. The most common use of raycasting is to determine the first object intersected by a ray. This is done by casting a virtual ray from a certain point in a direction and determining the first surface it intersected with.

In the middle of 2011, ROBLOX implemented the  method, which finds the first part a ray, represented by a   object, collides with when cast. It was already possible, using user-created algorithms, to implement this behavior, but such algorithms are usually very expensive in performance. Algorithms implemented at a lower level (in this case, in C++) are usually faster and more performant than algorithms at a higher level. Even with the  method, raycasting is still sufficiently slow to be avoided when not necessary.

ROBLOX has Ray values, which are used by the engine to represent the origin and direction of rays. These rays can be created with the  function:

The method, which is a method of the Workspace, returns two values: the part the ray hit, if it hit one, and the point at which the part was hit.

There is also another method that is almost identical to the  method, the   method, but with the difference that instead of having a parameter to ignore all the descendants of an object, it ignores all the descendants of objects in a table. This allows further customization of the parts that are ignored but is also slower.