basically i want to create a sound that gets louder the closer you are to a certain position, though I don’t want to do it through the sound properties I want to scale the volume proportionately to the distance between the player and the position. As the distance decreases, the volume increases basically.
Im stumped on how to do it and I could use some help, any is appreciated
You can use a linear formula for this.
but why not just use the built in 3D sound feature and parent the sound to a part or an attachment?
1 Like
the reason i dont wanna use the built in sound is because the volume doesnt scale at the rate i want it to scale at. It doesnt get loud enough when you get close to the part. Though the linear function did work thank you!!
You can try this:
while true do
local soundVolume -- the volume of the sound
local plrself = game.Players.LocalPlayer.HumanoidRootPart.Position -- player's position
local soundOrigin = game.workspace.Part.Position -- assign this to a basePart in workspace
local distance = (soundOrigin- self).Magnitude
wait()
if distance < (soundOrigin- plrself).Magnitude then -- if the player is moving away from the sound's origin
soundVolume = soundVolume - ((soundOrigin- plrself).Magnitude - distance) -- decrease the volume
end
if distance > (soundOrigin- plrself).Magnitude then -- if the player is moving to the sound's origin
soundVolume = soundVolume + ((soundOrigin- plrself).Magnitude - distance) -- increase the volume
end
end
1 Like