Skip to content

Commit

Permalink
Thruster sounds
Browse files Browse the repository at this point in the history
  • Loading branch information
jspahrsummers committed Jun 26, 2024
1 parent a323d90 commit f4362b8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER HIGH.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER LOW.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER MID.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER SEMI HIGH.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER VERY HIGH.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion ships/audio/THRUSTER VERY LOW.wav.import
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 6 additions & 2 deletions ships/player.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 12 additions & 0 deletions ships/ship.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
11 changes: 9 additions & 2 deletions ships/ship.tscn
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -13,14 +14,15 @@ 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
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)
Expand All @@ -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

0 comments on commit f4362b8

Please sign in to comment.