garrysmod-issues
garrysmod-issues copied to clipboard
IGModAudioChannel kinda breaks if the 3d channel position gets too close to the local player's eye position.
Details
I noticed when I was testing around that the audio kind of breaks when you set the channel position near or exactly to the eye position of the local client.
Broken/Setting it to the EyePos
https://github.com/user-attachments/assets/c1b77841-2f37-425d-8622-e629a0cb94af
Working/Setting it to the normal position:
https://github.com/user-attachments/assets/671bbfaf-5277-416f-8de2-fd8994b15a89
Steps to reproduce
sound.PlayFile("sound/slashco/music/slashco_offering_3.mp3", "3d", function(channel, errCode, errStr)
if not IsValid(channel) then
error("[SlashCo] Failed to create audio channel! (" .. errCode .. ", " .. errStr .. ")\n")
return
end
if IsValid(TESTCHANNEL) then
TESTCHANNEL:__gc()
end
TESTCHANNEL = channel
TESTCHANNEL:Play()
hook.Add("Think", "TestChannel", function()
if IsValid(TESTCHANNEL) then
TESTCHANNEL:SetPos(LocalPlayer():EyePos()) -- If changed to GetPos the audio will sound normal.
end
end)
end)
Example audio file from: https://github.com/Mantibro/SlashCo/blob/beta-changes/sound/slashco/music/slashco_offering_3.mp3
I am not sure this is really avoidable. You are setting the sound position to be right inside the listener's ear.
It just that the 2 positions (the sound origin and the ear/listener position) become slightly desynced causing the sound file to sound as if it was on the left or on the right very rapidly, because the 2 positions are ever so slightly different.
Lastly, I'd like to point out that it isn't really logical to do this, if you want a global sound, you don't make it 3D.
It is possible to set the sound file position in RenderScene hook (to render.GetViewSetup().origin), that would make it as synched as possible, but I'd like to reiterate how this is just not something you should be doing in general.
I did notice that setting it in PreRender seems to work far better, as it seems to not desync in there.
Could it be that CGMod_Audio::Update is maybe called before the Lua think hook, which could cause this desync?
Also, I will make them not be 3d when they don't have to be, this was just an issue I had found while playing around.
You just have to make it a global sound, it doesn't make sense to use 3d sound
You just have to make it a global sound, it doesn't make sense to use 3d sound
As already mentioned, I won't make them use 3d when they don't have to, like in this case. This was just something I found while playing around with the function.