I'm making a game where and AI can find you if you make too much noise, yada yada, basically, i need a mathematical formula that decides whether or not the volume is loud enough for the AI to hear. (Louder the sound, the farther away the sound can be hear and vise versa.)
I tried Volume * Magnitude, but if the sound volume was below 1, the AI would never hear you even if you are touching it, since multiplying by a decimal goes down.
Any other formulas I could try?
Here's my code
ReplicatedStorage.MakeSound.OnServerEvent:Connect(function(Player, SoundVolume)
if Chasing == false then
Magnitude = (HumanoidRootPart.Position - Player.Character:FindFirstChild("HumanoidRootPart").Position).Magnitude
SoundVolumeDistance = SoundVolume * Magnitude
print(SoundVolumeDistance .. " Volume Distance | Volume " .. SoundVolume .. " | Magnitude " .. Magnitude)
if SoundVolumeDistance >= Magnitude then
print("HE HAS HEARD YOU")
end
end
end)
The AI can hear anything louder than 1 with this script,

2 comments
My best go for this would be to fiddle with PlaybackLoudness of the players footstep sound and Distance range, although PlaybackLoudness could be completely unnecessary but that's my method if i were to ever do it.
Great question, man. +1 upvote.