big update, many changes

addefd some sound elements
changed the spatialaudio3d addon back so it it sounding okay
This commit is contained in:
Balogh Krisztián 2026-07-30 01:44:27 +02:00
parent 64c40d7bc3
commit 4869dcc3de
14 changed files with 221 additions and 115 deletions

View file

@ -39,8 +39,8 @@ class_name SpatialAudio3D extends AudioStreamPlayer3D
@export_flags_3d_physics var collision_mask: int = 1 ## Mask for the raycast where to add reverb. @export_flags_3d_physics var collision_mask: int = 1 ## Mask for the raycast where to add reverb.
@export var roomsize_multiplicator: float = 6.0 ## How much hall to add compared to room size.[br]Sometimes you have a small room but you need a long reverb. @export var roomsize_multiplicator: float = 6.0 ## How much hall to add compared to room size.[br]Sometimes you have a small room but you need a long reverb.
@export_range(1, 340, 1, "or_greater", "suffix:m/s") var speed_of_sound: int = 340 ## How fast sound travels through the air. @export_range(1, 340, 1, "or_greater", "suffix:m/s") var speed_of_sound: int = 340 ## How fast sound travels through the air.
@export var prox_reduction: float = 0.0 ## How much proximity reduces the reverb @export var prox_reduction: float = 24.0 ## How much proximity reduces the reverb
@export_range(4,32,1) var reverb_raycast_count: int = 8 ##how many reverb raycasts to shoot out horizontally @export_range(4,32,1) var reverb_raycast_count: int = 4 ##how many reverb raycasts to shoot out horizontally
@export_category("System") @export_category("System")
@export_range(1, 60, 0.1, "or_greater", "suffix:per second") var audiophysics_ticks: int = 10 ## The number of audio physics calculations per second.[br]Tied to _physics_process().[br][br]Use 30-60 for fast moving sounds like a motorcycle passing by.[br][br]Default: 10. @export_range(1, 60, 0.1, "or_greater", "suffix:per second") var audiophysics_ticks: int = 10 ## The number of audio physics calculations per second.[br]Tied to _physics_process().[br][br]Use 30-60 for fast moving sounds like a motorcycle passing by.[br][br]Default: 10.
@ -616,7 +616,6 @@ class Soundsource extends SpatialAudio3D:
_room_size += (distance / (max_raycast_distance / roomsize_multiplicator)) / float(total_rays) _room_size += (distance / (max_raycast_distance / roomsize_multiplicator)) / float(total_rays)
_room_size = snappedf(_room_size, 0.001) _room_size = snappedf(_room_size, 0.001)
_room_size = min(_room_size, 1.0) _room_size = min(_room_size, 1.0)
_room_size = max(_room_size, .4)
else: else:
# if a raycast did not hit anything we will reduce the reverb effect, almost no raycasts should hit when outdoors nowhere near buildings # if a raycast did not hit anything we will reduce the reverb effect, almost no raycasts should hit when outdoors nowhere near buildings
_wetness -= 1.0 / float(distances.size()) _wetness -= 1.0 / float(distances.size())

Binary file not shown.

View file

@ -0,0 +1,19 @@
[remap]
importer="mp3"
type="AudioStreamMP3"
uid="uid://0q6nhlhgnxu2"
path="res://.godot/imported/whitenoise.mp3-30a42016a56d56c9a5ec9a62706affe2.mp3str"
[deps]
source_file="res://assets/sounds/whitenoise.mp3"
dest_files=["res://.godot/imported/whitenoise.mp3-30a42016a56d56c9a5ec9a62706affe2.mp3str"]
[params]
loop=true
loop_offset=0
bpm=0
beat_count=0
bar_beats=4

30
default_bus_layout.tres Normal file
View file

@ -0,0 +1,30 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://bfh2c7jnwhac0"]
[sub_resource type="AudioEffectFilter" id="AudioEffectFilter_j3pel"]
resource_name = "Filter"
[sub_resource type="AudioEffectCompressor" id="AudioEffectCompressor_j3pel"]
resource_name = "Compressor"
[sub_resource type="AudioEffectHighPassFilter" id="AudioEffectHighPassFilter_j3pel"]
resource_name = "HighPassFilter"
cutoff_hz = 32.0
[sub_resource type="AudioEffectLimiter" id="AudioEffectLimiter_j3pel"]
resource_name = "Limiter"
[resource]
bus/1/name = &"wind"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.06726074
bus/1/send = &"Master"
bus/1/effect/0/effect = SubResource("AudioEffectFilter_j3pel")
bus/1/effect/0/enabled = true
bus/1/effect/1/effect = SubResource("AudioEffectCompressor_j3pel")
bus/1/effect/1/enabled = true
bus/1/effect/2/effect = SubResource("AudioEffectHighPassFilter_j3pel")
bus/1/effect/2/enabled = true
bus/1/effect/3/effect = SubResource("AudioEffectLimiter_j3pel")
bus/1/effect/3/enabled = true

View file

@ -1,7 +1,7 @@
[gd_scene format=3 uid="uid://chykk2a3opu0d"] [gd_scene format=3 uid="uid://chykk2a3opu0d"]
[ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="1_s8b7j"] [ext_resource type="PackedScene" uid="uid://kqq30y24c6kd" path="res://scenes/player/player.tscn" id="1_s8b7j"]
[ext_resource type="AudioStream" uid="uid://db0yck6trekrs" path="res://assets/sounds/ambiance/pc-fan-paulstretched.mp3" id="2_phkhq"] [ext_resource type="AudioStream" uid="uid://b6wlbiittcu48" path="res://assets/sounds/ambiance/harmonika-paulstretched.mp3" id="2_afrty"]
[ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"] [ext_resource type="Script" uid="uid://y8x4svl5kej2" path="res://addons/spatial_audio_3d/spatial_audio_3d.gd" id="4_yb1w3"]
[sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"] [sub_resource type="WorldBoundaryShape3D" id="WorldBoundaryShape3D_g4v7s"]
@ -74,7 +74,8 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1.2949467, -3.755646)
[node name="SpatialAudio3D" type="AudioStreamPlayer3D" parent="." unique_id=351573539] [node name="SpatialAudio3D" type="AudioStreamPlayer3D" parent="." unique_id=351573539]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.887349, 4.01754, -1.2293816) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 15.887349, 4.01754, -1.2293816)
stream = ExtResource("2_phkhq") stream = ExtResource("2_afrty")
volume_db = -8.235
autoplay = true autoplay = true
max_distance = 1927.53 max_distance = 1927.53
script = ExtResource("4_yb1w3") script = ExtResource("4_yb1w3")

View file

@ -20,8 +20,8 @@ extends Node
var sensitivity: float = 0.002 var sensitivity: float = 0.002
var _mouse_motion: Vector2 = Vector2.ZERO var mouse_motion: Vector2 = Vector2.ZERO
var _mouse_motion_delta: Vector2 = Vector2.ZERO var mouse_motion_delta: Vector2 = Vector2.ZERO
var held_object: RigidBody3D = null var held_object: RigidBody3D = null
@ -36,8 +36,8 @@ func _input(event):
if not player_state.in_menu: if not player_state.in_menu:
if event is InputEventMouseMotion: if event is InputEventMouseMotion:
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED: if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
_mouse_motion += event.relative mouse_motion += event.relative
_mouse_motion_delta = event.relative mouse_motion_delta = event.relative
if Input.is_action_just_pressed("flashlight"): if Input.is_action_just_pressed("flashlight"):
toggle_flashlight() toggle_flashlight()
@ -83,10 +83,10 @@ func _physics_process(delta: float) -> void:
held_object.angular_velocity = axis * angle * GRAB_ROTATION_POWER held_object.angular_velocity = axis * angle * GRAB_ROTATION_POWER
func _process(delta: float) -> void: func _process(delta: float) -> void:
_mouse_motion.y = clamp(_mouse_motion.y, -1560, 1560) mouse_motion.y = clamp(mouse_motion.y, -1560, 1560)
player.transform.basis = Basis.from_euler(Vector3(0, _mouse_motion.x * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0)) player.transform.basis = Basis.from_euler(Vector3(0, mouse_motion.x * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0))
camera.transform.basis = lerp(camera.transform.basis, Basis.from_euler(Vector3(_mouse_motion.y * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0, 0)), delta * 10) camera.transform.basis = lerp(camera.transform.basis, Basis.from_euler(Vector3(mouse_motion.y * -0.001 * procedural_camera_mover.LOOK_SENSITIVITY, 0, 0)), delta * 10)
#func _unhandled_input(event: InputEvent) -> void: #func _unhandled_input(event: InputEvent) -> void:
#if event is InputEventMouseMotion: #if event is InputEventMouseMotion:
#player_camera.rotate_y(-event.relative.x * sensitivity) #player_camera.rotate_y(-event.relative.x * sensitivity)

View file

@ -25,7 +25,6 @@ extends Node
@onready var sound_controller: Node = %SoundController @onready var sound_controller: Node = %SoundController
# Called when the node enters the scene tree for the first time.
func _ready() -> void: func _ready() -> void:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
@ -35,7 +34,6 @@ func _physics_process(delta: float) -> void:
if not player_state.in_menu: if not player_state.in_menu:
if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_properties.stamina > JUMP_STAMINA_COST: if Input.is_action_just_pressed("jump") and player.is_on_floor() and player_properties.stamina > JUMP_STAMINA_COST:
sound_controller.play_jump_sound()
player.velocity.y = JUMP_VELOCITY player.velocity.y = JUMP_VELOCITY
player_properties.stamina -= JUMP_STAMINA_COST player_properties.stamina -= JUMP_STAMINA_COST
player_properties.stamina_recharge_off() player_properties.stamina_recharge_off()
@ -86,12 +84,12 @@ func _physics_process(delta: float) -> void:
else: else:
player_state.is_walking(false) player_state.is_walking(false)
procedural_camera_mover.do(delta)
else: else:
player.velocity.x = lerpf(player.velocity.x, 0, delta * 10) player.velocity.x = lerpf(player.velocity.x, 0, delta * 10)
player.velocity.z = lerpf(player.velocity.z, 0, delta * 10) player.velocity.z = lerpf(player.velocity.z, 0, delta * 10)
player.move_and_slide() player.move_and_slide()
procedural_camera_mover.do(delta)
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta: float) -> void: #func _process(delta: float) -> void:

View file

@ -209,6 +209,7 @@
[ext_resource type="AudioStream" uid="uid://c8sksdmrqxcs1" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-009.mp3" id="201_8ri8i"] [ext_resource type="AudioStream" uid="uid://c8sksdmrqxcs1" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-009.mp3" id="201_8ri8i"]
[ext_resource type="AudioStream" uid="uid://c1h0kurf2ly1k" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-010.mp3" id="202_vlfn3"] [ext_resource type="AudioStream" uid="uid://c1h0kurf2ly1k" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-010.mp3" id="202_vlfn3"]
[ext_resource type="AudioStream" uid="uid://dkj34tqoqppml" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-011.mp3" id="203_klwgm"] [ext_resource type="AudioStream" uid="uid://dkj34tqoqppml" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-011.mp3" id="203_klwgm"]
[ext_resource type="AudioStream" uid="uid://0q6nhlhgnxu2" path="res://assets/sounds/whitenoise.mp3" id="204_76ube"]
[ext_resource type="AudioStream" uid="uid://bwsj7yir6tced" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-012.mp3" id="204_xfldr"] [ext_resource type="AudioStream" uid="uid://bwsj7yir6tced" path="res://assets/sounds/breathing/breathe_out/breathe_out_exhausted/Breathe-out-exhausted-012.mp3" id="204_xfldr"]
[sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"] [sub_resource type="CapsuleShape3D" id="CapsuleShape3D_g4v7s"]
@ -278,6 +279,7 @@ BREATHE_OUT_MID = Array[AudioStream]([ExtResource("166_2qmd4"), ExtResource("167
BREATHE_OUT_HEAVY = Array[AudioStream]([ExtResource("176_xb8ft"), ExtResource("177_mro88"), ExtResource("178_ya4ln"), ExtResource("179_yopjo"), ExtResource("180_wtqmm"), ExtResource("181_7cqnf"), ExtResource("182_q07wn"), ExtResource("183_72ejc"), ExtResource("184_m1gsv"), ExtResource("185_2yvq7")]) BREATHE_OUT_HEAVY = Array[AudioStream]([ExtResource("176_xb8ft"), ExtResource("177_mro88"), ExtResource("178_ya4ln"), ExtResource("179_yopjo"), ExtResource("180_wtqmm"), ExtResource("181_7cqnf"), ExtResource("182_q07wn"), ExtResource("183_72ejc"), ExtResource("184_m1gsv"), ExtResource("185_2yvq7")])
BREATHE_OUT_MAX = Array[AudioStream]([ExtResource("186_7qaaa"), ExtResource("187_yoiq4"), ExtResource("188_4anq4"), ExtResource("189_mkwaq"), ExtResource("190_0falv"), ExtResource("191_wvqjg"), ExtResource("192_xwj34")]) BREATHE_OUT_MAX = Array[AudioStream]([ExtResource("186_7qaaa"), ExtResource("187_yoiq4"), ExtResource("188_4anq4"), ExtResource("189_mkwaq"), ExtResource("190_0falv"), ExtResource("191_wvqjg"), ExtResource("192_xwj34")])
BREATHE_OUT_EXHAUSTED = Array[AudioStream]([ExtResource("193_2ggvy"), ExtResource("194_hvgvr"), ExtResource("195_c63qf"), ExtResource("196_nqymb"), ExtResource("197_n2wjg"), ExtResource("198_vh6pe"), ExtResource("199_0b2jo"), ExtResource("200_4ttds"), ExtResource("201_8ri8i"), ExtResource("202_vlfn3"), ExtResource("203_klwgm"), ExtResource("204_xfldr")]) BREATHE_OUT_EXHAUSTED = Array[AudioStream]([ExtResource("193_2ggvy"), ExtResource("194_hvgvr"), ExtResource("195_c63qf"), ExtResource("196_nqymb"), ExtResource("197_n2wjg"), ExtResource("198_vh6pe"), ExtResource("199_0b2jo"), ExtResource("200_4ttds"), ExtResource("201_8ri8i"), ExtResource("202_vlfn3"), ExtResource("203_klwgm"), ExtResource("204_xfldr")])
WHITENOISE = ExtResource("204_76ube")
[node name="UiHandler" type="Node" parent="Components" unique_id=1264775993] [node name="UiHandler" type="Node" parent="Components" unique_id=1264775993]
unique_name_in_owner = true unique_name_in_owner = true
@ -302,10 +304,25 @@ shape = SubResource("CapsuleShape3D_g4v7s")
[node name="CameraPivot" type="Node3D" parent="." unique_id=963377832] [node name="CameraPivot" type="Node3D" parent="." unique_id=963377832]
unique_name_in_owner = true unique_name_in_owner = true
[node name="Head" type="AudioStreamPlayer3D" parent="CameraPivot" unique_id=799817251]
unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.53598464, 0)
script = ExtResource("62_jbx34")
reverb_enabled = false
reverb_volume_db = -12.0
reverb_fadeintime = -1.0
reverb_fadeouttime = -1.0
metadata/_custom_type_script = "uid://y8x4svl5kej2"
[node name="HeadTexture" type="AudioStreamPlayer3D" parent="CameraPivot/Head" unique_id=732916843]
unique_name_in_owner = true
script = ExtResource("62_jbx34")
reverb_enabled = false
metadata/_custom_type_script = "uid://y8x4svl5kej2"
[node name="PlayerCamera" type="Camera3D" parent="CameraPivot" unique_id=303347613] [node name="PlayerCamera" type="Camera3D" parent="CameraPivot" unique_id=303347613]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.75045073, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.69669175, 0)
current = true
[node name="Flashlight" type="SpotLight3D" parent="CameraPivot/PlayerCamera" unique_id=1036641941] [node name="Flashlight" type="SpotLight3D" parent="CameraPivot/PlayerCamera" unique_id=1036641941]
unique_name_in_owner = true unique_name_in_owner = true
@ -336,6 +353,7 @@ shape = SubResource("CylinderShape3D_g4v7s")
[node name="PlayerListener" type="AudioListener3D" parent="CameraPivot" unique_id=1468948553] [node name="PlayerListener" type="AudioListener3D" parent="CameraPivot" unique_id=1468948553]
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7621309, 0) transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.7621309, 0)
doppler_tracking = 2 doppler_tracking = 2
current = true
[node name="PlayerUi" parent="." unique_id=454848358 instance=ExtResource("2_rkbax")] [node name="PlayerUi" parent="." unique_id=454848358 instance=ExtResource("2_rkbax")]
unique_name_in_owner = true unique_name_in_owner = true
@ -417,21 +435,10 @@ reverb_fadeintime = -1.0
reverb_fadeouttime = -1.0 reverb_fadeouttime = -1.0
metadata/_custom_type_script = "uid://y8x4svl5kej2" metadata/_custom_type_script = "uid://y8x4svl5kej2"
[node name="Head" type="AudioStreamPlayer3D" parent="SoundEmitters" unique_id=799817251] [node name="Wind" type="AudioStreamPlayer" parent="SoundEmitters" unique_id=1598731400]
unique_name_in_owner = true unique_name_in_owner = true
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.53598464, 0) stream = ExtResource("204_76ube")
script = ExtResource("62_jbx34") bus = &"wind"
reverb_enabled = false
reverb_volume_db = -12.0
reverb_fadeintime = -1.0
reverb_fadeouttime = -1.0
metadata/_custom_type_script = "uid://y8x4svl5kej2"
[node name="HeadTexture" type="AudioStreamPlayer3D" parent="SoundEmitters/Head" unique_id=732916843]
unique_name_in_owner = true
script = ExtResource("62_jbx34")
reverb_enabled = false
metadata/_custom_type_script = "uid://y8x4svl5kej2"
[connection signal="body_entered" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_entered"] [connection signal="body_entered" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_entered"]
[connection signal="body_exited" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_exited"] [connection signal="body_exited" from="CameraPivot/PlayerCamera/GrabbableFinder" to="Components/UiHandler" method="_on_grabbable_finder_body_exited"]

View file

@ -3,9 +3,6 @@ extends Node
@export_category("Inventory") @export_category("Inventory")
@export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory @export var INVENTORY_MAX = 3 ##max number of items that can be in the player's inventory
@export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory @export var INVENTORY_ITEMS: Array = [] ##the items in the player's inventory
@onready var ui_handler: Node = %UiHandler
var stamina: float = 100.0 var stamina: float = 100.0
var selected_item: int = 0 var selected_item: int = 0
@ -30,7 +27,6 @@ func prev_item():
func select_item(index:int): func select_item(index:int):
selected_item = index selected_item = index
ui_handler.update_inventory_ui()
emit_signal("selected_item_changed") emit_signal("selected_item_changed")
func get_selected_item() -> PackedScene: func get_selected_item() -> PackedScene:

View file

@ -3,30 +3,3 @@ extends Control
@onready var stamina_bar: ProgressBar = %StaminaBar @onready var stamina_bar: ProgressBar = %StaminaBar
@onready var inventory_slots_panels: Array = [%InvSlot1, %InvSlot2, %InvSlot3] @onready var inventory_slots_panels: Array = [%InvSlot1, %InvSlot2, %InvSlot3]
var inventory: Array = [null,null,null] var inventory: Array = [null,null,null]
#var inventory: Array = [null,null,null]
#
#var stamina: float = 100
#var selected_item: int = 0
#
#const SELECTED_COLOR = 0xcfcfcf78
#const UNSELECTED_COLOR = 0x3d3d3d78
#
#func set_stamina_bar(value:float):
#stamina = value
#
#func get_selected_item() -> PackedScene:
#return inventory[selected_item]
#
#func select_item(index: int):
#inventory_slots_panels[selected_item].color = Color.hex(UNSELECTED_COLOR)
#selected_item = index
#inventory_slots_panels[index].color = Color.hex(SELECTED_COLOR)
#
#func put_item(index: int, item: PackedScene):
#inventory[index] = item
#
#func _process(delta: float) -> void:
#stamina_bar.value = lerpf(stamina_bar.value, stamina, delta * 5)
#
#func set_ui_scale(scale:float) -> void:
#pass

View file

@ -6,7 +6,7 @@ extends Node
@export var CAMERA_BOB_FREQUENCY = 2.4 ##how quick the camera bobs whilst moving @export var CAMERA_BOB_FREQUENCY = 2.4 ##how quick the camera bobs whilst moving
@export var CAMERA_BOB_AMPLITUDE = 0.08 ##how hard the camera bobs whilst moving @export var CAMERA_BOB_AMPLITUDE = 0.08 ##how hard the camera bobs whilst moving
@export var CAMERA_BOB_MULTIPLIER = 200.0 ##how much the ui reacts to head bobbing @export var CAMERA_BOB_MULTIPLIER = 200.0 ##how much the ui reacts to head bobbing
@export var CAMERA_SIDEWAYS_BOB_AMPLITUDE = 0.003 ## how many degrees does the camera bob sideways @export var CAMERA_SIDEWAYS_BOB_AMPLITUDE = 0.03 ## how many degrees does the camera bob sideways
@export_category("UI") @export_category("UI")
@export var UI_SCALE: float = 1 ##rational scale of the ui @export var UI_SCALE: float = 1 ##rational scale of the ui
@ -21,6 +21,8 @@ extends Node
@onready var player_properties: Node = %PlayerProperties @onready var player_properties: Node = %PlayerProperties
@onready var ui_base_position = ui.position @onready var ui_base_position = ui.position
@onready var ui_handler: Node = %UiHandler @onready var ui_handler: Node = %UiHandler
@onready var player_state: Node = %PlayerState
@onready var input_controller: Node = %InputController
var t_bob: float = 0.0 var t_bob: float = 0.0
var last_bob_y: float = 0.0 var last_bob_y: float = 0.0
@ -28,8 +30,6 @@ var t_breath: float = 0.0
var last_breath_y: float = 0.0 var last_breath_y: float = 0.0
var _camera_original_position: Vector3 = Vector3(0,.75,0) var _camera_original_position: Vector3 = Vector3(0,.75,0)
var _mouse_motion: Vector2 = Vector2.ZERO
var _mouse_motion_delta: Vector2 = Vector2.ZERO
var _last_camera_global_position: Vector3 = Vector3.ZERO var _last_camera_global_position: Vector3 = Vector3.ZERO
var _breathing: bool = true var _breathing: bool = true
@ -42,37 +42,39 @@ func _process(delta: float) -> void:
else: else:
_breathing = false _breathing = false
camera_breathing(delta) footstep_sound()
breathing_sound()
func do(delta): func do(delta):
ui.offset_transform_scale *= UI_SCALE ui.offset_transform_scale *= UI_SCALE
ui_movement_handling(delta) ui_movement_handling(delta)
ui_handler.set_stamina_bar(player_properties.stamina) ui_handler.set_stamina_bar(player_properties.stamina)
var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length() var horizontal_speed = Vector3(player.velocity.x, player.velocity.y, player.velocity.z).length()
var current_sin_pos = sin(t_bob * CAMERA_BOB_FREQUENCY) if _breathing:
t_breath += delta * (100 / (40 + player_properties.stamina))
var target_pos = get_breathing_bob_offset_pos()
var target_rot = get_breathing_bob_offset_rot()
if player.is_on_floor() and horizontal_speed > 0.05: if player.is_on_floor() and horizontal_speed > 0.05:
t_bob += delta * (player.velocity.length() * float(player.is_on_floor()) + (int(Input.is_action_pressed("crouch"))) * 3) t_bob += delta * (player.velocity.length() * float(player.is_on_floor()) + (int(Input.is_action_pressed("crouch"))) * 3)
#footstep handling target_pos += get_moving_bob_offset_pos()
if last_bob_y >= -.95 and current_sin_pos < -.95: target_rot += get_moving_bob_offset_rot()
sound_controller.play_footstep_sound()
last_bob_y = current_sin_pos camera.transform.origin = camera.transform.origin.lerp(target_pos, delta * 10)
camera_bobbing(t_bob) var final_pitch = camera.rotation.x + target_rot.x
var final_roll = target_rot.z
else:
camera.rotation.z = lerpf(camera.rotation.z,0, delta * 0.004) var target_basis = Basis.from_euler(Vector3(final_pitch, 0, final_roll))
camera.transform.origin.y = lerpf(camera.transform.origin.y, _camera_original_position.y, delta * 5.0)
if camera.transform.origin.length() < 0.01: camera.transform.basis = camera.transform.basis.slerp(target_basis, delta * 5)
t_bob = 0
last_bob_y = 0.0
func ui_movement_handling(delta: float): func ui_movement_handling(delta: float):
var mouse_offset = -_mouse_motion_delta * UI_MOVEMENT_SENSITIVITY var mouse_offset = -input_controller.mouse_motion_delta * UI_MOVEMENT_SENSITIVITY
var current_camera_global_position = camera.global_position var current_camera_global_position = camera.global_position
var camera_global_velocity = (current_camera_global_position - _last_camera_global_position) / delta var camera_global_velocity = (current_camera_global_position - _last_camera_global_position) / delta
@ -96,13 +98,16 @@ func ui_movement_handling(delta: float):
ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * UI_MOVEMENT_SENSITIVITY * 0.003, delta * UI_MOVEMENT_SPEED) ui.offset_transform_rotation = lerpf(ui.offset_transform_rotation, ui_rotation_target * UI_MOVEMENT_SENSITIVITY * 0.003, delta * UI_MOVEMENT_SPEED)
func camera_bobbing(time: float): func footstep_sound():
camera.transform.origin.y = sin(time * CAMERA_BOB_FREQUENCY) * CAMERA_BOB_AMPLITUDE + .75 var current_sin_pos = sin(t_bob * CAMERA_BOB_FREQUENCY)
camera.rotation.z += sin(time * CAMERA_BOB_FREQUENCY * .5) * CAMERA_SIDEWAYS_BOB_AMPLITUDE
if last_bob_y >= -.95 and current_sin_pos < -.95:
sound_controller.play_footstep_sound()
last_bob_y = current_sin_pos
func camera_breathing(time: float): func breathing_sound():
if _breathing: if _breathing:
t_breath += time * (100 / (40 + player_properties.stamina))
var current_sin_pos = sin(t_breath * CAMERA_BOB_FREQUENCY) var current_sin_pos = sin(t_breath * CAMERA_BOB_FREQUENCY)
if last_breath_y <= -.60 and current_sin_pos > -.60: if last_breath_y <= -.60 and current_sin_pos > -.60:
@ -112,7 +117,15 @@ func camera_breathing(time: float):
sound_controller.play_breath_sound(false) sound_controller.play_breath_sound(false)
last_breath_y = current_sin_pos last_breath_y = current_sin_pos
camera.transform.origin.y = sin(time * CAMERA_BOB_FREQUENCY) * CAMERA_BOB_AMPLITUDE + .75 func get_breathing_bob_offset_pos() -> Vector3:
camera.rotation.x += sin(time * CAMERA_BOB_FREQUENCY) * CAMERA_SIDEWAYS_BOB_AMPLITUDE return Vector3(0, sin(t_breath * CAMERA_BOB_FREQUENCY) * CAMERA_BOB_AMPLITUDE + .75, 0)
func get_breathing_bob_offset_rot() -> Vector3:
return Vector3(sin(t_breath * CAMERA_BOB_FREQUENCY) * CAMERA_SIDEWAYS_BOB_AMPLITUDE, 0, 0)
func get_moving_bob_offset_pos() -> Vector3:
return Vector3(0, sin(t_bob * CAMERA_BOB_FREQUENCY) * CAMERA_BOB_AMPLITUDE, 0)
func get_moving_bob_offset_rot() -> Vector3:
return Vector3(0, 0, sin(t_bob * CAMERA_BOB_FREQUENCY * .5) * CAMERA_SIDEWAYS_BOB_AMPLITUDE)

View file

@ -29,6 +29,8 @@ extends Node
@export var BREATHE_OUT_MAX: Array[AudioStream] @export var BREATHE_OUT_MAX: Array[AudioStream]
@export var BREATHE_OUT_EXHAUSTED: Array[AudioStream] @export var BREATHE_OUT_EXHAUSTED: Array[AudioStream]
@export_group("Whitenoise")
@export var WHITENOISE: AudioStream
var _current_flashlight_sound = null var _current_flashlight_sound = null
var _current_footstep_sound = null var _current_footstep_sound = null
@ -41,27 +43,59 @@ var _current_breath_out_sound = null
var _current_leg_is_right = false var _current_leg_is_right = false
@onready var player_state: Node = %PlayerState @onready var player_state: Node = %PlayerState
@onready var player: PlayerCharacter = $"../.."
@onready var input_controller: Node = %InputController
@onready var left_foot: SpatialAudio3D = %LeftFoot @onready var left_foot: SpatialAudio3D = %LeftFoot
@onready var right_foot: SpatialAudio3D = %RightFoot @onready var right_foot: SpatialAudio3D = %RightFoot
@onready var right_foot_texture: SpatialAudio3D = %RightFootTexture @onready var right_foot_texture: SpatialAudio3D = %RightFootTexture
@onready var left_foot_texture: SpatialAudio3D = %LeftFootTexture @onready var left_foot_texture: SpatialAudio3D = %LeftFootTexture
@onready var head: SpatialAudio3D = %Head @onready var head: SpatialAudio3D = %Head
@onready var head_texture: SpatialAudio3D = %HeadTexture @onready var head_texture: SpatialAudio3D = %HeadTexture
@onready var player: PlayerCharacter = $"../.." @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????")
## TODO figure out why the sound keeps cutting off when var debug: bool = false
## shit changes, like the player_property.breathing_mode, even though its change should not change the sound of the stream but still does for some reason?? var reverb: bool = true
var debug: bool = true
func _ready() -> void: func _ready() -> void:
left_foot.debug = debug var sound_players:Array[SpatialAudio3D] = [left_foot, left_foot_texture, right_foot, right_foot_texture, head, head_texture]
right_foot.debug = debug
right_foot_texture.debug = debug for i in sound_players:
left_foot_texture.debug = debug i.debug = debug
head.debug = debug i.reverb_enabled = reverb
head_texture.debug = debug
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()
var is_right_leg := func () -> SpatialAudio3D: var is_right_leg := func () -> SpatialAudio3D:
if _current_leg_is_right: if _current_leg_is_right:
@ -93,14 +127,16 @@ func create_spatial_audio_sphere(pos:Vector3, audio:AudioStream, pitch:float = 1
elif is_instance_valid(spatial_audio): elif is_instance_valid(spatial_audio):
spatial_audio.queue_free() spatial_audio.queue_free()
func play_stream_on_player(player:SpatialAudio3D, audio:AudioStream, pitch: float = randf_range(.8, 1.2)): func play_stream_on_player(player:SpatialAudio3D, audio:AudioStream, pitch: float = randf_range(.8, 1.2), volume = 1.0):
if player.finished: if not is_instance_valid(player) or audio == null:
player.process_mode = Node.PROCESS_MODE_INHERIT return
if audio_cooldowns[get_player_str.call(player)] <= 0:
player.do_set_stream(audio) player.do_set_stream(audio)
player.pitch_scale = pitch player.pitch_scale = pitch
player.volume_db = player.volume_db * volume
player.do_play() player.do_play()
await get_tree().create_timer(3).timeout audio_cooldowns[get_player_str.call(player)] = audio.get_length() / 1.5
player.process_mode = Node.PROCESS_MODE_DISABLED
func play_breath_sound(breathe_in:bool = true): func play_breath_sound(breathe_in:bool = true):
var play_sound var play_sound
@ -153,6 +189,9 @@ func play_flashlight_sound():
func play_jump_sound(start:bool = true): func play_jump_sound(start:bool = true):
var sound_to_play_foot: AudioStream = null var sound_to_play_foot: AudioStream = null
var sound_to_play_breath: AudioStream = null var sound_to_play_breath: AudioStream = null
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)
match start: match start:
true: true:
@ -161,12 +200,13 @@ func play_jump_sound(start:bool = true):
while sound_to_play_breath == _current_jump_start_breath_sound: while sound_to_play_breath == _current_jump_start_breath_sound:
sound_to_play_breath = JUMP_STARTING_BREATH_SOUNDS.pick_random() sound_to_play_breath = JUMP_STARTING_BREATH_SOUNDS.pick_random()
false: false:
print(volume)
while sound_to_play_foot == _current_jump_land_sound: while sound_to_play_foot == _current_jump_land_sound:
sound_to_play_foot = JUMP_LANDING_SOUNDS.pick_random() sound_to_play_foot = JUMP_LANDING_SOUNDS.pick_random()
while sound_to_play_breath == _current_jump_land_breath_sound: while sound_to_play_breath == _current_jump_land_breath_sound:
sound_to_play_breath = JUMP_LANDING_BREATH_SOUNDS.pick_random() sound_to_play_breath = JUMP_LANDING_BREATH_SOUNDS.pick_random()
play_stream_on_player(head, sound_to_play_breath) play_stream_on_player(head, sound_to_play_breath, randf_range(.8, 1.2), volume)
play_stream_on_player(is_right_leg.call(), sound_to_play_foot) play_stream_on_player(is_right_leg.call(), sound_to_play_foot)
func play_footstep_sound(): func play_footstep_sound():
@ -189,3 +229,24 @@ func play_footstep_sound():
_current_footstep_sound = sound_to_play _current_footstep_sound = sound_to_play
play_stream_on_player(is_right_leg.call(), sound_to_play) play_stream_on_player(is_right_leg.call(), sound_to_play)
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

View file

@ -24,6 +24,11 @@ enum breath {
var _breath_change_points: Array[float] = [10, 20, 50, 80] var _breath_change_points: Array[float] = [10, 20, 50, 80]
@onready var player_properties: Node = %PlayerProperties @onready var player_properties: Node = %PlayerProperties
@onready var player: PlayerCharacter = $"../.."
var flying: bool = false
signal landed
signal jumped
func _process(_delta: float) -> void: func _process(_delta: float) -> void:
var stamina = player_properties.stamina var stamina = player_properties.stamina
@ -39,6 +44,14 @@ func _process(_delta: float) -> void:
breathing_mode = breath.low breathing_mode = breath.low
else: else:
breathing_mode = breath.calm breathing_mode = breath.calm
if !player.is_on_floor() and !flying:
emit_signal("jumped", true)
flying = true
if player.is_on_floor() and flying:
emit_signal("landed", false)
flying = false
func is_crouched(yes:bool): func is_crouched(yes:bool):
if yes: if yes:

View file

@ -35,12 +35,8 @@ func _on_grabbable_finder_body_exited(body: Node3D) -> void:
grabbable_panel = null grabbable_panel = null
grabbable_panel_body = null grabbable_panel_body = null
func update_inventory_ui():
set_selected_item(player_properties.selected_item)
func _ready() -> void: func _ready() -> void:
player_properties.selected_item_changed.connect(update_inventory_ui) player_properties.selected_item_changed.connect(set_selected_item)
update_inventory_ui()
func _process(delta: float) -> void: func _process(delta: float) -> void:
ui.stamina_bar.value = lerpf(ui.stamina_bar.value, player_properties.stamina, delta * 5) ui.stamina_bar.value = lerpf(ui.stamina_bar.value, player_properties.stamina, delta * 5)
@ -67,7 +63,7 @@ func toggle_menu():
func set_stamina_bar(value:float): func set_stamina_bar(value:float):
ui.stamina_bar.value = value ui.stamina_bar.value = value
func set_selected_item(index: int): func set_selected_item():
for i in len(ui.inventory_slots_panels): for i in len(ui.inventory_slots_panels):
if i == player_properties.selected_item: if i == player_properties.selected_item:
ui.inventory_slots_panels[i].color = Color.hex(SELECTED_COLOR) ui.inventory_slots_panels[i].color = Color.hex(SELECTED_COLOR)