From f4362b8b8954fc97a42e113d409d147568a6acb7 Mon Sep 17 00:00:00 2001 From: Justin Spahr-Summers Date: Wed, 26 Jun 2024 12:17:59 +0100 Subject: [PATCH] Thruster sounds --- ships/audio/THRUSTER HIGH.wav.import | 2 +- ships/audio/THRUSTER LOW.wav.import | 2 +- ships/audio/THRUSTER MID.wav.import | 2 +- ships/audio/THRUSTER SEMI HIGH.wav.import | 2 +- ships/audio/THRUSTER VERY HIGH.wav.import | 2 +- ships/audio/THRUSTER VERY LOW.wav.import | 2 +- ships/player.gd | 8 ++++++-- ships/ship.gd | 12 ++++++++++++ ships/ship.tscn | 11 +++++++++-- 9 files changed, 33 insertions(+), 10 deletions(-) diff --git a/ships/audio/THRUSTER HIGH.wav.import b/ships/audio/THRUSTER HIGH.wav.import index 519e5637..ad700443 100644 --- a/ships/audio/THRUSTER HIGH.wav.import +++ b/ships/audio/THRUSTER HIGH.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/audio/THRUSTER LOW.wav.import b/ships/audio/THRUSTER LOW.wav.import index 60334367..bb12f4e6 100644 --- a/ships/audio/THRUSTER LOW.wav.import +++ b/ships/audio/THRUSTER LOW.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/audio/THRUSTER MID.wav.import b/ships/audio/THRUSTER MID.wav.import index c9f4d5bf..3c307f9d 100644 --- a/ships/audio/THRUSTER MID.wav.import +++ b/ships/audio/THRUSTER MID.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/audio/THRUSTER SEMI HIGH.wav.import b/ships/audio/THRUSTER SEMI HIGH.wav.import index c08f4e9f..03d5a4f9 100644 --- a/ships/audio/THRUSTER SEMI HIGH.wav.import +++ b/ships/audio/THRUSTER SEMI HIGH.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/audio/THRUSTER VERY HIGH.wav.import b/ships/audio/THRUSTER VERY HIGH.wav.import index 129b719d..b17a45c4 100644 --- a/ships/audio/THRUSTER VERY HIGH.wav.import +++ b/ships/audio/THRUSTER VERY HIGH.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/audio/THRUSTER VERY LOW.wav.import b/ships/audio/THRUSTER VERY LOW.wav.import index fa746d41..7e5248b3 100644 --- a/ships/audio/THRUSTER VERY LOW.wav.import +++ b/ships/audio/THRUSTER VERY LOW.wav.import @@ -18,7 +18,7 @@ force/max_rate=false force/max_rate_hz=44100 edit/trim=false edit/normalize=false -edit/loop_mode=0 +edit/loop_mode=2 edit/loop_begin=0 edit/loop_end=-1 compress/mode=0 diff --git a/ships/player.gd b/ships/player.gd index 39310659..7d1355ca 100644 --- a/ships/player.gd +++ b/ships/player.gd @@ -64,13 +64,17 @@ func _physics_process(_delta: float) -> void: match UserPreferencesSystem.control_scheme: UserPreferencesSystem.ControlScheme.RELATIVE: if Input.is_action_pressed("thrust"): - apply_central_force(self.transform.basis * Vector3.FORWARD * self.ship_def.thrust) + self.thrust_step(1.0) + else: + self.thrust_stopped() UserPreferencesSystem.ControlScheme.ABSOLUTE: var desired_direction := self._absolute_input_direction() var current_direction := - self.transform.basis.z if desired_direction != Vector3.ZERO and desired_direction.angle_to(current_direction) <= ABSOLUTE_DIRECTION_TOLERANCE_RAD: - apply_central_force(self.transform.basis * Vector3.FORWARD * self.ship_def.thrust * desired_direction.length()) + self.thrust_step(desired_direction.length()) + else: + self.thrust_stopped() if Input.is_action_pressed("fire"): self.fire() diff --git a/ships/ship.gd b/ships/ship.gd index 19907fb5..2e96c548 100644 --- a/ships/ship.gd +++ b/ships/ship.gd @@ -4,6 +4,7 @@ class_name Ship @export var ship_def: ShipDef @export var bullet: PackedScene @export var explosion: PackedScene +@export var thruster_audio: AudioStreamPlayer3D var hull: float var shield: float @@ -63,3 +64,14 @@ func explode() -> void: CombatSystem.notify_ship_destroyed(self) self.queue_free() + +func thrust_step(magnitude: float) -> void: + if self.thruster_audio.stream_paused: + self.thruster_audio.stream_paused = false + elif !self.thruster_audio.playing: + self.thruster_audio.play() + + self.apply_central_force(self.transform.basis * Vector3.FORWARD * self.ship_def.thrust * magnitude) + +func thrust_stopped() -> void: + self.thruster_audio.stream_paused = true diff --git a/ships/ship.tscn b/ships/ship.tscn index 8d777d80..4ea486a5 100644 --- a/ships/ship.tscn +++ b/ships/ship.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://cqxv07b8bwiev"] +[gd_scene load_steps=8 format=3 uid="uid://cqxv07b8bwiev"] [ext_resource type="Script" path="res://ships/ship.gd" id="1_wioy5"] [ext_resource type="ArrayMesh" uid="uid://40a23nnu1j37" path="res://ships/corvette01/corvette01_mesh.tres" id="1_yacfo"] [ext_resource type="PackedScene" uid="uid://cdyo800b83x5i" path="res://effects/explosions/explosion002.tscn" id="2_xcc1t"] +[ext_resource type="AudioStream" uid="uid://5iqc5o8p02l5" path="res://ships/audio/THRUSTER LOW.wav" id="4_xrdjv"] [sub_resource type="SphereShape3D" id="SphereShape3D_kf5ql"] @@ -13,7 +14,7 @@ shading_mode = 0 material = SubResource("StandardMaterial3D_t5loa") orientation = 1 -[node name="Ship" type="RigidBody3D" groups=["ships"]] +[node name="Ship" type="RigidBody3D" node_paths=PackedStringArray("thruster_audio") groups=["ships"]] transform = Transform3D(1, -3.48787e-16, 3.48787e-16, 3.48787e-16, 1, -3.48787e-16, -3.48787e-16, 3.48787e-16, 1, 0, 0, 0) collision_mask = 2 axis_lock_linear_y = true @@ -21,6 +22,7 @@ axis_lock_angular_x = true axis_lock_angular_z = true script = ExtResource("1_wioy5") explosion = ExtResource("2_xcc1t") +thruster_audio = NodePath("AudioStreamPlayer3D") [node name="CollisionShape3D" type="CollisionShape3D" parent="."] transform = Transform3D(0.2, 0, 0, 0, 0.2, 0, 0, 0, 0.2, 0, 0, 0) @@ -34,3 +36,8 @@ skeleton = NodePath("") [node name="MinimapIcon" type="MeshInstance3D" parent="."] layers = 2 mesh = SubResource("QuadMesh_lxgwo") + +[node name="AudioStreamPlayer3D" type="AudioStreamPlayer3D" parent="."] +transform = Transform3D(1, -1.21652e-31, 0, -1.21652e-31, 1, 0, 0, 0, 1, -6.21724e-17, 6.21724e-17, 0.178253) +stream = ExtResource("4_xrdjv") +volume_db = -40.0