I wanna make volumetric sound system. Basically shoot rays, reflect em N amount times and create new emitters, but for some reason it always going wrong
local COS = math.cos
local SIN = math.sin
local RAD = math.rad
local EXP = math.exp
local ABS = math.abs
local RANDOM = math.random
local SOUNDEMITTER_FOLDER = workspace:FindFirstChild("SoundEmitters") or Instance.new("Folder")
SOUNDEMITTER_FOLDER.Name = "SoundEmitters"
local function RandomCFrame()
math.randomseed(os.clock())
return CFrame.Angles(
RAD(RANDOM(0,360)),
RAD(RANDOM(0,360)),
RAD(RANDOM(0,360))
)
end
local function RandomCFrameInDirection(direction, range)
direction = direction.unit
local theta = RAD(RANDOM()*360)
local phi = RAD((RANDOM()*range)-(range/2))
local x = COS(theta)*COS(phi)
local y = SIN(phi)
local z = SIN(theta)*COS(phi)
return CFrame.lookAt(direction, direction + Vector3.new(x,y,z), Vector3.new(0,1,0))
end
function SWS.PropogateSoundWaves(p)
local SoundEmitter = p.sound or p.soundemitter or p.Sound or p.SoundEmitter
local SoundEmitterLifeTime = p.soundlifetime or p.soundemitterlifetime or p.SoundLifetime or p.SoundEmitterLifetime
local NumRays = p.rays or p.Rays or p.NumberOfRays or p.numberofrays
local NumReflections = p.reflections or p.Reflections or p.NumberOfReflections or p.numberofreflections
local Direction = p.direction or p.Direction or p.dir or p.Dir
local Range = p.range or p.Range
Main problem: Instancing new Sound Emitters, calculating Volume and PlaybackSpeed
Baically sound occlusion with reverb and echo, using raycasts and material lookup table.