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

GetPartsObscuringTarget

This function returns an array of BasePart|BaseParts that are obscuring the lines of sight between Camera|Camera’s Camera/CFrame and the castPoints.

GetPartsObscuringTarget is used by the ‘Invisicam’ in in the default camera scripts to hide parts between the Camera|Camera’s Camera/CFrame and Camera/Focus.

Any Instance|Instances included in the ignoreList array will, along with their descendants, be ignored.

See below for a visual example of this function. The Camera is represented by the grey camera model and the cast points are represented by the colored dots. The Part|Parts highlighted in red are the ones that would be returned.

A visual demonstration of the function

The castPoints parameter is given as an array of DataType/Vector3|Vector3s, for example:

local castPoints = {Vector3.new(0, 10, 0), Vector3.new(0, 15, 0)}
local ignoreList = {}
workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList)

The array of BasePart|BaseParts returned is in an arbitrary order, and no additional raycast data is provided (for example hit position, hit material and surface normal). If this information is required, you should a Workspace raycast function such as Workspace/FindPartOnRayWithIgnoreList.

If Terrain obscures a cast point, BasePart|BaseParts obscuring the cast point between the obscuring Terrain and the cast point will not be returned.

Note, this function benefits from internal optimisations that make it more performant than casting a ray for each cast point individually.

Parameters

Name Type Default Description

An array of DataType/Vector3 positions of cast points

An array of Instance|Instances that, along with their descendants, are to be ignored

Returns

Return Type Summary

An array of BasePart|BaseParts that obscure the lines of sight between the Camera|Camera’s Camera/CFrame and the castPoints


Code Samples


X-Ray Function

This function will make any BasePart|BaseParts, Decal|Decals or Texture|Textures coming between the Workspace/CurrentCamera and the given cast points translucent.

local function XRay(castPoints, ignoreList)
	ignoreList = ignoreList or {}
	local parts = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList)

	for _, part in pairs(parts) do
		part.LocalTransparencyModifier = 0.75
		for _, child in pairs(part:GetChildren()) do
			if child:IsA("Decal") or child:IsA("Texture") then
				child.LocalTransparencyModifier = 0.75
			end
		end
	end
end