extends Node const audible_threshold = 5 const dropoff_threshold = 50 const max_vol = 0 const min_vol = -20 func _ready(): add_streams("res://sound/basketball/", $SFX/Basketball) func add_streams(res_directory: String, node: Node): var index = 0 for file_name in DirAccess.get_files_at(res_directory): if file_name.ends_with(".ogg"): node.stream.add_stream(index, load(res_directory + file_name), 1) index += 1 func impact_noise(velocity: Vector2): var averaged_velocity = (velocity.x + velocity.y) / 2 if velocity.y > audible_threshold: $SFX/Basketball.volume_db = (clamp(averaged_velocity, 0, dropoff_threshold) / dropoff_threshold) * (max_vol - min_vol) + min_vol $SFX/Basketball.play()