From 52517fac05c875309e5c17dd74ac4520472fb06d Mon Sep 17 00:00:00 2001 From: teatov Date: Sun, 13 Oct 2024 15:51:38 +1000 Subject: [PATCH] add a custom audio listener --- scenes/world.tscn | 4 ++-- scripts/main_camera.gd | 12 +++++++++--- scripts/units/aphid.gd | 3 ++- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/scenes/world.tscn b/scenes/world.tscn index 8440eaa..2745363 100644 --- a/scenes/world.tscn +++ b/scenes/world.tscn @@ -196,7 +196,7 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, -50.9454, -8.10623e-06, -60.0 gizmo_extents = 4.7 script = ExtResource("3_vkmt5") what = 1 -amount = 30 +amount = 0 [node name="UI" type="Node" parent="."] @@ -216,7 +216,7 @@ fov = 37.8493 script = ExtResource("1_gnxhh") [node name="AudioListener3D" type="AudioListener3D" parent="MainCamera"] -current = true +top_level = true [node name="AmbientAudio" type="AudioStreamPlayer" parent="."] process_mode = 3 diff --git a/scripts/main_camera.gd b/scripts/main_camera.gd index 968e4af..93888a6 100644 --- a/scripts/main_camera.gd +++ b/scripts/main_camera.gd @@ -53,11 +53,14 @@ var state: CameraState = CameraState.FREE var window_out_of_focus: bool = false @onready var attrs: CameraAttributesPractical = attributes +@onready var listener: AudioListener3D = $AudioListener3D func _ready() -> void: assert(attrs != null, "attrs missing!") + assert(listener != null, "listener missing!") target_position = StaticNodesManager.player_anthill.global_position + listener.make_current() func _process(delta: float) -> void: @@ -67,17 +70,20 @@ func _process(delta: float) -> void: zoom_value = lerpf(zoom_value, zoom_unsmoothed, delta * ZOOM_DAMP) fov = lerpf(zoom_in_fov, zoom_out_fov, zoom_value) - rotation.x = lerpf(zoom_in_angle, zoom_out_angle, zoom_value) + global_rotation.x = lerpf(zoom_in_angle, zoom_out_angle, zoom_value) var distance: float = lerpf(zoom_in_distance, zoom_out_distance, zoom_value) - var offset_direction := Vector3.BACK.rotated(Vector3.RIGHT, rotation.x) + var offset_direction := Vector3.BACK.rotated(Vector3.RIGHT, global_rotation.x) var offset := offset_direction * distance global_position = target_position + offset + listener.global_position = target_position + (Vector3.UP * distance) + listener.global_rotation = global_rotation _handle_dof() _handle_advance_anim_step() DebugManager.marker(target_position, 0.05) + DebugManager.marker(listener.global_position, 0.05, Color.GREEN) func _input(event: InputEvent) -> void: @@ -180,7 +186,7 @@ func _handle_movement(delta: float) -> void: var direction := ( Vector3(move_input.x, 0, move_input.y) - .rotated(Vector3.UP, rotation.y) + .rotated(Vector3.UP, global_rotation.y) ) var speed: float = lerpf(zoom_in_speed, zoom_out_speed, zoom_value) diff --git a/scripts/units/aphid.gd b/scripts/units/aphid.gd index 368945d..d7b81ec 100644 --- a/scripts/units/aphid.gd +++ b/scripts/units/aphid.gd @@ -50,7 +50,8 @@ func _handle_honeydew_spawn(delta: float) -> void: if honeydew_spawn_timer >= 0: honeydew_spawn_timer -= delta return - + + audio_player.play_sound(SoundManager.pop()) var new_honeydew := honeydew_scene.instantiate() as Honeydew new_honeydew.set_aphid(self)