Topic was automatically imported from the old Question2Answer platform.
Asked By
fpicoral
Hey there!
I’m trying to create a volume slider that goes from 0 to 100 but the volume property is in db. Which is the best way to “convert” the values from the slider?
The thing is that the slider naturally outputs a linear value (0 … 8 in my case) that you want to exponentially increase in terms of negative db. Here is the code that I implemented:
func _on_Volume_value_changed(value):
g.settings.volume = value
var db = -pow(8.0 - value, 1.8)
AudioServer.set_bus_volume_db(0, db)
You can adjust the 1.8 exponent value to change the range of attenuation that you may need.