Developer knowledge network ยท moderated exchange

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Knowledge indexLive
4Categories
919Threads
2.8KPosts
Tutorial

Luau Raycast Collision Filtering with RaycastParams for Wall-Check Visibility [v2.4 Technical Discussion]

raycast_ryan
Ballistics Dev
MEMBER
Rep: 72
Join Date: Sep 2019
Posts: 32
Thanks: 16
1 months ago ยท Jul 15, 2026 1:05 AM
#1

Verifying target visibility before firing in Luau:

LUA
local function IsVisible(targetHead, localHead, targetCharacter, localCharacter)
    local params = RaycastParams.new()
    params.FilterType = RaycastFilterType.Exclude
    params.FilterDescendantsInstances = { localCharacter, targetCharacter }
    params.IgnoreWater = true
    
    local origin = localHead.Position
    local direction = targetHead.Position - origin
    local result = workspace:Raycast(origin, direction, params)
    
    -- If ray hits no obstacles, player is directly visible
    return result == nil
end
matrix_math_guy
Math Specialist
MEMBER
Rep: 105
Join Date: Aug 2018
Posts: 52
Thanks: 41
1 months ago ยท Jul 15, 2026 5:28 AM
#2

Excluding both the local character and target character in FilterDescendantsInstances prevents false wall-occlusion triggers from accessories.

luau_hacker
Luau Expert
MEMBER
Rep: 159
Join Date: Aug 2020
Posts: 17
Thanks: 26
1 months ago ยท Jul 15, 2026 1:36 PM
#3

Clean and performant.