Developer knowledge network · moderated exchange

مجتمع الكود غير الموثوق به

أبحاث المطورين، مجتمع الهندسة العكسية والترميز

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 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
مندوب: 105
تاريخ الانضمام: Aug 2018
دعامات: 52
شكرًا: 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
مندوب: 159
تاريخ الانضمام: Aug 2020
دعامات: 17
شكرًا: 26
1 months ago · Jul 15, 2026 1:36 PM
#3

Clean and performant.