I just finished the One-Time sound effects lesson for the godot 4 2D class. However, the jump sound is too loud. Is there a way to change that volume via code?
Morning,
you an tweak the volume of the audiostream player using its volume_db property.
this property is 0 by default, so probably a -5 would lower it a bit.
just done a quick test and this is how i done it.
since were creating a new audiostreamplayer each time to create the SFX, we would have to set the property each time.
what you can do is have an export variable, just so that you can set it with a slider.
if you pop this at the top of the audioplayer.gd script
# -- Just to have hints in the inspector --
@export_category("Audio Settings")
@export_range(-10,10,0.1)
var jump_sfx_volume : float = 0
then just after we create the stream player, or just before we call add_child(asp), we can check to see if its the jump thats being played, if it is, then adjust the volume
#this is the bit ive added in to set the volume for the player,
#just for the jump audio
if stream == jump:
asp.volume_db = jump_sfx_volume
its just a little trickier with this one, since were only wanting to change the volume for a single SFX rather than the whole audio player.
hope that helps you out.
This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.