Not to burst your bubble, but the engine is already capable of handling this.
Attached is a sample file of a sound rotating around the origin with Rolloff settings in SoundService set to exaggerate the effect. (Careful the sound may be a bit loud on some audio devices) EngineAttenuation.rbxl (15.5 KB)
What does your module do that isn’t already being done passively by Roblox?
Upon further testing with @sidnad10, we have determined that Rolloff handles based on distance, not angle relative to the camera LookVector. It simply makes sounds quieter the farther away they are. The fact that you think it is “behind” you is simply your brain interpreting it’s path to predict that it’s circling “around” you. This module is made to actually simulate how your ears interpret directional sounds.
You can prove this by having the object switch between a few studs in front and a few studs behind at random intervals. Close your eyes, and you’ll find yourself unable to tell when it is switching. Here, feel free to try it. BlindTest.rbxl (18.7 KB)
Whereas the same test, but using the module, shows clear difference between front and back. BlindTestModule.rbxl (20.2 KB)
for the HighGain calculation provides a much nicer and more realistic result.
The original edition had it dampen linearly, which meant that the sides were half-dampened.
This is an inSine ease, so it dampens more behind you than to the sides.
Files have been updated with this, and I recommend anyone who has already implemented this to insert the new file. API hasn’t changed, so you can just replace the module without any issues.
I can’t hear the difference between BlindTest vs BlindTestModule and your game vs EngineAttenuation. Do you have any other examples that might be clearer?
I would suggest also adding an function to attach an audio to this, so it can support all audios rather than just audios created by the script. I am going to modify the code to fit my use by doing this and if people are interested, I can link it here.
Here’s the code I used (Posted directly after :Create() function)
function SoundSystem:Attach(sound)
local Equalizer = sound:FindFirstChildOfClass("EqualizerSoundEffect") or newInst("EqualizerSoundEffect")
Equalizer.LowGain = 0
Equalizer.MidGain = 0
Equalizer.HighGain = 0
Equalizer.Parent = sound
local tbl = {Sound = sound}
CurrentObjects[tbl] = true
spawn(function()
repeat wait() until not sound:IsDescendantOf(workspace)
CurrentObjects[tbl] = nil
end)
end
Edit: I would like to add that this has not been tested, and will be pending testing until I have properly incorporated my Vehicle Physics into the file with this.
I don’t have access to my PC for a few days, but I plan on adding this feature to the master branch.
I do plan on rewriting the code, but the API is nice. I just think creating a thread to do a repeat wait() until is not the best way to accomplish that.
I made this for a StreamingEnabled environment, so it works pretty well for me. I use this quite often without seeing any sort of memory issues or anything related to that. I suppose you could do wait(1) if you are concerned.
I haven’t tested it, but this may break if someone uses the system and changes a user’s listener - although I’m not sure many people use it, it can be used to change where a user ‘hears’ from.
local listenerType, listener = game:GetService("SoundService"):GetListener()
You seem to use the angle to the user’s camera to do the effects, so if the player is listening from somewhere else, it won’t work correctly. (unless you’ve changed something since I’ve last looked.)