RaycastParams

Constructors

NameDescription
new()Creates a new, blank RaycastParams object with default values for all properties. Properties can then be set on it and it can be reused across multiple raycasts.

Code Snippet

local params = RaycastParams.new()
params.ExcludeInstances = {player.Character}
params.IgnoreWater = true

local origin = camera.CFrame.Position
local direction = camera.CFrame.LookVector * 100

local result = workspace:Raycast(origin, direction, params)
if result then
    print("Hit:", result.Instance:GetFullName(), "at", result.Position)
end

Properties

NameTypeDescription
ExcludeInstances{Instance}?An optional array of instances whose descendants will be excluded from the raycast query.
IncludeInstances{Instance}?An optional array of instances whose descendants will be the only ones included in the raycast query.
IgnoreWaterbooleanDetermines whether Terrain water is considered during the raycast.
CollisionGroupstringThe name of the collision group to raycast against. Defaults to "Default" if not set.
RespectCanCollidebooleanWhen true, a part's CanCollide property is also used (in addition to CanQuery) to determine whether it can be hit by the raycast.
BruteForceAllSlowbooleanWhen true, ignores CanQuery/CanCollide filtering entirely and checks every part. Significantly hurts performance and is intended only for debugging.
FilterDescendantsInstancesArrayAn array of instances whose descendants are used to filter raycast candidates, combined with FilterType. Superseded by ExcludeInstances/IncludeInstances but still supported.
FilterTypeEnum.RaycastFilterTypeDetermines whether FilterDescendantsInstances is treated as an exclude list or an include list. Superseded by ExcludeInstances/IncludeInstances but still supported.

Methods

NameParametersReturnsDescription
AddToFilter(instances: Instance | {Instance})Instances: Instance or array of InstanceVoidAdds one or more instances to FilterDescendantsInstances without needing to reassign the whole array.