← Back to Portal Hub

Rekayasa Audio 3D Roblox: Hierarki SoundGroups, Zona Reverb & Oklusi Raycast

By DopaBrain Studio Engineering Team • 2026-09-30 • Technical Guide

Dalam game 3D multiplayer, audio memegang peranan penting dalam menciptakan imersi. Efek suara 2D datar yang terdengar menembus tembok tanpa peredaman merusak pengalaman bermain.

Roblox menyediakan fitur mumpuni melalui SoundService. Dengan mengatur SoundGroups, kurva RollOff, dan raycast untuk filter LowPass, Anda dapat menghadirkan kualitas audio 3D kelas atas.

1. Hierarki SoundGroups dan Struktur Mixing Profesional

Mengatur bus audio agar suara efek dan musik tetap seimbang:

2. Atenuasi Jarak 3D dan Kurva RollOff

Perambatan suara secara fisik untuk deteksi arah yang akurat:

Manajer Audio Spasial Luau: Oklusi Raycast dan Zona Reverb
--!strict
local Workspace = game:GetService("Workspace")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")

local SpatialAudioManager = {}
type OccludedSound = { sound: Sound, emitterPart: BasePart, lowPass: LowPassSoundEffect, originalVolume: number }
local trackedSounds: { OccludedSound } = {}
local RAY_PARAMS = RaycastParams.new()
RAY_PARAMS.FilterType = RaycastFilterType.Exclude

function SpatialAudioManager.RegisterOccludedSound(sound: Sound, emitter: BasePart)
    local lpf = sound:FindFirstChildOfClass("LowPassSoundEffect") or Instance.new("LowPassSoundEffect")
    lpf.CutoffFrequency = 20000
    lpf.Parent = sound
    table.insert(trackedSounds, { sound = sound, emitterPart = emitter, lowPass = lpf, originalVolume = sound.Volume })
end

function SpatialAudioManager.UpdateOcclusion(camera: Camera)
    local listenerPos = camera.CFrame.Position
    RAY_PARAMS.FilterDescendantsInstances = { camera }
    for _, item in ipairs(trackedSounds) do
        if not item.sound.IsPlaying then continue end
        local dir = item.emitterPart.Position - listenerPos
        if dir.Magnitude > item.sound.RollOffMaxDistance then continue end
        local hit = Workspace:Raycast(listenerPos, dir, RAY_PARAMS)
        local occluded = hit and hit.Instance and hit.Instance ~= item.emitterPart and hit.Instance.CanCollide
        local cutoff = occluded and 1200 or 20000
        local vol = occluded and (item.originalVolume * 0.45) or item.originalVolume
        TweenService:Create(item.lowPass, TweenInfo.new(0.25), { CutoffFrequency = cutoff }):Play()
        TweenService:Create(item.sound, TweenInfo.new(0.25), { Volume = vol }):Play()
    end
end
return SpatialAudioManager

3. Oklusi Suara Raycast: Efek Meredam di Balik Tembok

Mencegah suara langkah kaki terdengar jernih saat terhalang tembok tebal:

4. Zona Reverb Lingkungan Dinamis

Peralihan gema yang mulus antara gua, koridor, dan ruang terbuka:

5. Manajemen Kanal Audio dan Efisiensi Mobile

Memastikan suara stabil tanpa terpotong di perangkat ponsel:

Frequently Asked Questions

Mengapa harus file audio mono untuk suara 3D?

File stereo memakan memori ganda dan sering mengalami pembatalan fase saat diposisikan di ruang 3D.

Apakah raycast audio menyebabkan lag?

Jika dibatasi hanya untuk suara dekat, proses ini memakan waktu kurang dari 0.1 ms per frame.

Bagaimana agar BGM tidak ikut bergema di dalam gua?

Pisahkan BGM ke dalam SoundGroup khusus yang tidak terhubung ke efek lingkungan.

Explore More Interactive Tests & Guides

Discover personalized cognitive assessments, stress evaluations, and game psychology tools on DopaBrain.

Go to Portal Hub