PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience
Collapse Sidebar

FindPartOnRayWithWhitelist

Returns the first BasePart intersecting with the given DataType/Ray that is in, or descendant of an object in, the given white-list.

This function also returns the position of intersection, the surface normal of the intersecting BasePart at the point of intersection, and the BasePart's BasePart/Material.

The ignoreWater parameter determines whether water will be ignored or not. This only applies if the Workspace's Terrain has been included in the white-list, as otherwise water is ignored along with terrain regardless.

This function is a variant of Workspace/FindPartOnRay with the addition of a whitelist. This allows the developer to only look at certain BaseParts or Models. This can be particularly useful when, for example, looking for points of intersection between a ray and a single BasePart.

local function getIntersection(part, ray)
	local whiteList = {part}
	local _, position, normal = workspace:FindPartOnRayWithWhitelist(ray, whiteList)
	return position, normal
end

Those looking to utilize an ignore list instead should use Workspace/FindPartOnRayWithIgnoreList.

Notes

  • Theoretically, a ray extends infinitely in one direction. However, the max length of the direction vector on Roblox is 5000 studs
  • The length of the direction vector is important - parts further away than its length will not be tested
  • If the ray does not intersect a part, the return values will be nil and the point at the end of the ray, respectively
  • If a nil value is given in the white list, instances after this value will be disregarded
  • Parts that are in a PhysicsService/SetPartCollisionGroup|collision group that does not collide with the “Default” collision group are ignored implicitly

For more information on how raycasting works in Roblox, please see the articles on raycasting basics and how to make raycasting guns.

Parameters

Name Type Default Description

ray

Ray

The DataType/Ray.

An array of objects to be checked.

false

True if terrain water should be ignored.

Returns

Return Type Summary

The BasePart (or Terrain) hit, the DataType/Vector3 point of intersection, the DataType/Vector3 surface normal at the point of intersection and the Enum/Material of the BasePart or terrain cell hit.