2026-07-29 00:05:40 +02:00
|
|
|
extends Node
|
|
|
|
|
|
|
|
|
|
@export_category("Audio")
|
|
|
|
|
@export var AUDIO_LOUDNESS: float = 100.0
|
|
|
|
|
@export var NORMAL_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##normal footsteps -- walking
|
|
|
|
|
@export var HEAVY_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##heavy footsteps -- running
|
|
|
|
|
@export var LIGHT_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##light footsteps -- crouching
|
|
|
|
|
@export var FLASHLIGHT_CLICK_SOUNDS: Array[AudioStreamWAV] ##flashlight click
|
2026-07-29 02:37:45 +02:00
|
|
|
@export var SHUFFLE_FOOTSTEP_SOUNDS: Array[AudioStreamWAV] ##shuffling -- random chance of playing while running
|
2026-07-29 00:05:40 +02:00
|
|
|
@export var SHUFFLE_CHANCE: float = 20 ##percentage of chance for a shuffle noise to be played whilst running
|
|
|
|
|
|
2026-07-29 02:37:45 +02:00
|
|
|
@export var JUMP_LANDING_SOUNDS: Array[AudioStream]
|
|
|
|
|
@export var JUMP_STARTING_SOUNDS: Array[AudioStream]
|
|
|
|
|
@export var JUMP_LANDING_BREATH_SOUNDS: Array[AudioStream]
|
|
|
|
|
@export var JUMP_STARTING_BREATH_SOUNDS: Array[AudioStream]
|
|
|
|
|
|
|
|
|
|
@export_group("Breathing")
|
|
|
|
|
@export var BREATHE_IN_CALM: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_IN_LOW: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_IN_MID: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_IN_HEAVY: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_IN_MAX: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_IN_EXHAUSTED: Array[AudioStream]
|
|
|
|
|
|
|
|
|
|
@export var BREATHE_OUT_CALM: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_OUT_LOW: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_OUT_MID: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_OUT_HEAVY: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_OUT_MAX: Array[AudioStream]
|
|
|
|
|
@export var BREATHE_OUT_EXHAUSTED: Array[AudioStream]
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
@export_group("Whitenoise")
|
|
|
|
|
@export var WHITENOISE: AudioStream
|
2026-07-29 02:37:45 +02:00
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
var _current_flashlight_sound = null
|
|
|
|
|
var _current_footstep_sound = null
|
2026-07-29 02:37:45 +02:00
|
|
|
var _current_jump_start_sound = null
|
|
|
|
|
var _current_jump_start_breath_sound = null
|
|
|
|
|
var _current_jump_land_sound = null
|
|
|
|
|
var _current_jump_land_breath_sound = null
|
|
|
|
|
var _current_breath_in_sound = null
|
|
|
|
|
var _current_breath_out_sound = null
|
2026-07-29 00:05:40 +02:00
|
|
|
var _current_leg_is_right = false
|
|
|
|
|
|
|
|
|
|
@onready var player_state: Node = %PlayerState
|
2026-07-31 02:38:02 +02:00
|
|
|
@onready var player: CharacterBody3D = $"../.."
|
2026-07-30 01:44:27 +02:00
|
|
|
@onready var input_controller: Node = %InputController
|
|
|
|
|
|
2026-07-29 02:37:45 +02:00
|
|
|
@onready var left_foot: SpatialAudio3D = %LeftFoot
|
2026-07-29 00:05:40 +02:00
|
|
|
@onready var right_foot: SpatialAudio3D = %RightFoot
|
|
|
|
|
@onready var right_foot_texture: SpatialAudio3D = %RightFootTexture
|
2026-07-29 02:37:45 +02:00
|
|
|
@onready var left_foot_texture: SpatialAudio3D = %LeftFootTexture
|
|
|
|
|
@onready var head: SpatialAudio3D = %Head
|
|
|
|
|
@onready var head_texture: SpatialAudio3D = %HeadTexture
|
2026-07-30 01:44:27 +02:00
|
|
|
@onready var wind: AudioStreamPlayer = %Wind
|
|
|
|
|
|
|
|
|
|
var audio_cooldowns = {
|
|
|
|
|
"left_foot": 0,
|
|
|
|
|
"right_foot": 0,
|
|
|
|
|
"right_foot_texture": 0,
|
|
|
|
|
"left_foot_texture": 0,
|
|
|
|
|
"head": 0,
|
|
|
|
|
"head_texture": 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var get_player_str = func (player:SpatialAudio3D):
|
|
|
|
|
match player:
|
|
|
|
|
left_foot: return "left_foot"
|
|
|
|
|
right_foot: return "right_foot"
|
|
|
|
|
right_foot_texture: return "right_foot_texture"
|
|
|
|
|
left_foot_texture: return "left_foot_texture"
|
|
|
|
|
head: return "head"
|
|
|
|
|
head_texture: return "head_texture"
|
|
|
|
|
_: push_error("problem in get_player_str in sound_controller_component.gd. fuck????")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var debug: bool = false
|
|
|
|
|
var reverb: bool = true
|
2026-07-29 02:37:45 +02:00
|
|
|
|
|
|
|
|
func _ready() -> void:
|
2026-07-30 01:44:27 +02:00
|
|
|
var sound_players:Array[SpatialAudio3D] = [left_foot, left_foot_texture, right_foot, right_foot_texture, head, head_texture]
|
|
|
|
|
|
|
|
|
|
for i in sound_players:
|
|
|
|
|
i.debug = debug
|
|
|
|
|
i.reverb_enabled = reverb
|
|
|
|
|
|
|
|
|
|
get_tree().create_timer(1).timeout.connect(init_wind)
|
|
|
|
|
|
|
|
|
|
player_state.landed.connect(play_jump_sound)
|
|
|
|
|
player_state.jumped.connect(play_jump_sound)
|
|
|
|
|
|
|
|
|
|
func _process(delta: float) -> void:
|
|
|
|
|
if audio_cooldowns != null:
|
|
|
|
|
for i in audio_cooldowns:
|
|
|
|
|
if audio_cooldowns[i] > 0:
|
|
|
|
|
audio_cooldowns[i] -= delta
|
|
|
|
|
|
|
|
|
|
play_wind()
|
2026-07-29 02:37:45 +02:00
|
|
|
|
|
|
|
|
var is_right_leg := func () -> SpatialAudio3D:
|
|
|
|
|
if _current_leg_is_right:
|
2026-07-29 13:52:14 +02:00
|
|
|
_current_leg_is_right = !_current_leg_is_right
|
2026-07-29 02:37:45 +02:00
|
|
|
return right_foot
|
|
|
|
|
else:
|
2026-07-29 13:52:14 +02:00
|
|
|
_current_leg_is_right = !_current_leg_is_right
|
2026-07-29 02:37:45 +02:00
|
|
|
return left_foot
|
|
|
|
|
|
|
|
|
|
##only use for sparse effects
|
|
|
|
|
func create_spatial_audio_sphere(pos:Vector3, audio:AudioStream, pitch:float = 1.0):
|
|
|
|
|
var spatial_audio = SpatialAudio3D.new()
|
|
|
|
|
spatial_audio.collision_mask = 1
|
|
|
|
|
|
|
|
|
|
spatial_audio.stream = audio
|
|
|
|
|
|
|
|
|
|
add_child(spatial_audio)
|
|
|
|
|
|
|
|
|
|
spatial_audio.global_position = pos
|
|
|
|
|
|
|
|
|
|
if is_instance_valid(spatial_audio) and audio != null:
|
|
|
|
|
spatial_audio.do_play()
|
|
|
|
|
spatial_audio.get_child(0).name = audio.resource_name
|
|
|
|
|
|
|
|
|
|
await get_tree().create_timer(audio.get_length() + 2).timeout
|
|
|
|
|
|
|
|
|
|
if is_instance_valid(spatial_audio):
|
|
|
|
|
spatial_audio.queue_free()
|
|
|
|
|
elif is_instance_valid(spatial_audio):
|
|
|
|
|
spatial_audio.queue_free()
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
func play_stream_on_player(player:SpatialAudio3D, audio:AudioStream, pitch: float = randf_range(.8, 1.2), volume = 1.0):
|
|
|
|
|
if not is_instance_valid(player) or audio == null:
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
if audio_cooldowns[get_player_str.call(player)] <= 0:
|
2026-07-29 13:52:14 +02:00
|
|
|
player.do_set_stream(audio)
|
|
|
|
|
player.pitch_scale = pitch
|
2026-07-30 01:44:27 +02:00
|
|
|
player.volume_db = player.volume_db * volume
|
2026-07-29 13:52:14 +02:00
|
|
|
player.do_play()
|
2026-07-30 01:44:27 +02:00
|
|
|
audio_cooldowns[get_player_str.call(player)] = audio.get_length() / 1.5
|
2026-07-29 02:37:45 +02:00
|
|
|
|
|
|
|
|
func play_breath_sound(breathe_in:bool = true):
|
|
|
|
|
var play_sound
|
|
|
|
|
if breathe_in:
|
|
|
|
|
play_sound = _current_breath_in_sound
|
|
|
|
|
while play_sound == _current_breath_in_sound:
|
|
|
|
|
match player_state.breathing_mode:
|
|
|
|
|
player_state.breath.calm:
|
|
|
|
|
play_sound = BREATHE_IN_CALM.pick_random()
|
|
|
|
|
player_state.breath.low:
|
|
|
|
|
play_sound = BREATHE_IN_LOW.pick_random()
|
|
|
|
|
player_state.breath.mid:
|
|
|
|
|
play_sound = BREATHE_IN_MID.pick_random()
|
|
|
|
|
player_state.breath.heavy:
|
|
|
|
|
play_sound = BREATHE_IN_HEAVY.pick_random()
|
|
|
|
|
player_state.breath.max:
|
|
|
|
|
play_sound = BREATHE_IN_MAX.pick_random()
|
|
|
|
|
player_state.breath.exhausted:
|
|
|
|
|
play_sound = BREATHE_IN_EXHAUSTED.pick_random()
|
|
|
|
|
_current_breath_in_sound = play_sound
|
|
|
|
|
else:
|
|
|
|
|
play_sound = _current_breath_out_sound
|
|
|
|
|
while play_sound == _current_breath_out_sound:
|
|
|
|
|
match player_state.breathing_mode:
|
|
|
|
|
player_state.breath.calm:
|
|
|
|
|
play_sound = BREATHE_OUT_CALM.pick_random()
|
|
|
|
|
player_state.breath.low:
|
|
|
|
|
play_sound = BREATHE_OUT_LOW.pick_random()
|
|
|
|
|
player_state.breath.mid:
|
|
|
|
|
play_sound = BREATHE_OUT_MID.pick_random()
|
|
|
|
|
player_state.breath.heavy:
|
|
|
|
|
play_sound = BREATHE_OUT_HEAVY.pick_random()
|
|
|
|
|
player_state.breath.max:
|
|
|
|
|
play_sound = BREATHE_OUT_MAX.pick_random()
|
|
|
|
|
player_state.breath.exhausted:
|
|
|
|
|
play_sound = BREATHE_OUT_EXHAUSTED.pick_random()
|
|
|
|
|
_current_breath_out_sound = play_sound
|
|
|
|
|
|
|
|
|
|
play_stream_on_player(head, play_sound)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
|
|
|
|
func play_flashlight_sound():
|
|
|
|
|
var play_sound = FLASHLIGHT_CLICK_SOUNDS.pick_random()
|
|
|
|
|
|
|
|
|
|
while play_sound == _current_flashlight_sound:
|
|
|
|
|
play_sound = FLASHLIGHT_CLICK_SOUNDS.pick_random()
|
|
|
|
|
|
2026-07-29 02:37:45 +02:00
|
|
|
play_stream_on_player(head_texture, play_sound)
|
2026-07-29 00:05:40 +02:00
|
|
|
_current_flashlight_sound = play_sound
|
2026-07-29 02:37:45 +02:00
|
|
|
|
|
|
|
|
func play_jump_sound(start:bool = true):
|
|
|
|
|
var sound_to_play_foot: AudioStream = null
|
|
|
|
|
var sound_to_play_breath: AudioStream = null
|
2026-07-30 01:44:27 +02:00
|
|
|
var volume:float = 1.0
|
|
|
|
|
|
|
|
|
|
##TODO: make the landing sound volume scale with the fallen height (the higher you fall from, the bigger the stomp)
|
2026-07-29 00:05:40 +02:00
|
|
|
|
2026-07-29 13:52:14 +02:00
|
|
|
match start:
|
2026-07-29 02:37:45 +02:00
|
|
|
true:
|
|
|
|
|
while sound_to_play_foot == _current_jump_start_sound:
|
|
|
|
|
sound_to_play_foot = JUMP_STARTING_SOUNDS.pick_random()
|
|
|
|
|
while sound_to_play_breath == _current_jump_start_breath_sound:
|
|
|
|
|
sound_to_play_breath = JUMP_STARTING_BREATH_SOUNDS.pick_random()
|
|
|
|
|
false:
|
2026-07-30 01:44:27 +02:00
|
|
|
print(volume)
|
2026-07-29 02:37:45 +02:00
|
|
|
while sound_to_play_foot == _current_jump_land_sound:
|
|
|
|
|
sound_to_play_foot = JUMP_LANDING_SOUNDS.pick_random()
|
|
|
|
|
while sound_to_play_breath == _current_jump_land_breath_sound:
|
|
|
|
|
sound_to_play_breath = JUMP_LANDING_BREATH_SOUNDS.pick_random()
|
|
|
|
|
|
2026-07-30 01:44:27 +02:00
|
|
|
play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume)
|
2026-07-29 02:37:45 +02:00
|
|
|
play_stream_on_player(is_right_leg.call(), sound_to_play_foot)
|
|
|
|
|
|
2026-07-29 00:05:40 +02:00
|
|
|
func play_footstep_sound():
|
2026-07-29 02:37:45 +02:00
|
|
|
var sound_to_play:AudioStream
|
2026-07-29 00:05:40 +02:00
|
|
|
if player_state.walking:
|
|
|
|
|
sound_to_play = NORMAL_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
while sound_to_play == _current_footstep_sound:
|
|
|
|
|
sound_to_play = NORMAL_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
elif player_state.running:
|
|
|
|
|
sound_to_play = HEAVY_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
while sound_to_play == _current_footstep_sound:
|
|
|
|
|
sound_to_play = HEAVY_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
if randf_range(1, 100) > 100 - SHUFFLE_CHANCE:
|
2026-07-29 02:37:45 +02:00
|
|
|
play_stream_on_player(is_right_leg.call().get_child(0), SHUFFLE_FOOTSTEP_SOUNDS.pick_random())
|
2026-07-29 00:05:40 +02:00
|
|
|
elif player_state.crouching:
|
|
|
|
|
sound_to_play = LIGHT_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
while sound_to_play == _current_footstep_sound:
|
|
|
|
|
sound_to_play = LIGHT_FOOTSTEP_SOUNDS.pick_random()
|
|
|
|
|
|
|
|
|
|
_current_footstep_sound = sound_to_play
|
|
|
|
|
|
2026-07-29 02:37:45 +02:00
|
|
|
play_stream_on_player(is_right_leg.call(), sound_to_play)
|
2026-07-30 01:44:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
var wind_filter: AudioEffectFilter
|
|
|
|
|
var wind_strength: float = 0 ## set the strength of the base wind, VERY SENSITIVE
|
|
|
|
|
|
|
|
|
|
func init_wind():
|
|
|
|
|
var bus_idx = AudioServer.get_bus_index("wind")
|
|
|
|
|
wind_filter = AudioServer.get_bus_effect(bus_idx,0)
|
|
|
|
|
|
|
|
|
|
wind.volume_db = -80
|
|
|
|
|
wind.play()
|
|
|
|
|
|
|
|
|
|
func play_wind():
|
|
|
|
|
var strength = player.velocity.length() * 10 + abs(player.velocity.y) * 15
|
|
|
|
|
var mouse_strength = input_controller.mouse_motion_delta.length() * 5
|
|
|
|
|
|
|
|
|
|
if wind_filter is AudioEffectFilter:
|
|
|
|
|
wind_filter.cutoff_hz = strength / 2 + mouse_strength / 10 + wind_strength
|
|
|
|
|
wind_filter.resonance = 0.5
|
|
|
|
|
|
|
|
|
|
wind.volume_linear = strength / 100 + mouse_strength / 10000 + wind_strength
|