Developer knowledge network · moderated exchange

Супольнасць UnreliableCode

Супольнасць распрацоўшчыкаў даследаванняў, зваротнага праектавання і кадавання

Knowledge indexжыць
4Categories
919Threads
2.8KПаведамленні
Tutorial

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

raycast_ryan
Ballistics Dev
MEMBER
прадстаўнік: 72
Дата далучэння: Sep 2019
Паведамленні: 32
Дзякуй: 16
1 месяцаў таму · 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
прадстаўнік: 105
Дата далучэння: Aug 2018
Паведамленні: 52
Дзякуй: 41
1 месяцаў таму · 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
прадстаўнік: 159
Дата далучэння: Aug 2020
Паведамленні: 17
Дзякуй: 26
1 месяцаў таму · Jul 15, 2026 1:36 PM
#3

Clean and performant.