2.16 controlling audio with scripts

This commit is contained in:
david 2025-02-09 14:19:19 +01:00
parent 9f8a76b98b
commit 08553f798f
4 changed files with 32 additions and 1 deletions

Binary file not shown.

View file

@ -0,0 +1,19 @@
[remap]
importer="oggvorbisstr"
type="AudioStreamOggVorbis"
uid="uid://dyf7x2qy7lww"
path="res://.godot/imported/SFX - Main engine thrust.ogg-e61c489157b52b29e5e5f5deefca83f3.oggvorbisstr"
[deps]
source_file="res://resources/audio/SFX - Main engine thrust.ogg"
dest_files=["res://.godot/imported/SFX - Main engine thrust.ogg-e61c489157b52b29e5e5f5deefca83f3.oggvorbisstr"]
[params]
loop=true
loop_offset=0.0
bpm=0.0
beat_count=0
bar_beats=4

View file

@ -12,11 +12,13 @@ public partial class Player : RigidBody3D
private AudioStreamPlayer deathAudioPlayer;
private AudioStreamPlayer successAudioPlayer;
private AudioStreamPlayer3D rocketAudioPlayer;
public override void _Ready()
{
deathAudioPlayer = GetNode<AudioStreamPlayer>("DeathAudioPlayer");
successAudioPlayer = GetNode<AudioStreamPlayer>("SuccessAudioPlayer");
rocketAudioPlayer = GetNode<AudioStreamPlayer3D>("RocketAudioPlayer");
BodyEntered += OnPlayerCollision;
ZLeft = new Vector3(0, 0, torque);
ZRight = new Vector3(0, 0, -torque);
@ -26,6 +28,11 @@ public partial class Player : RigidBody3D
float fd = (float)delta;
if (Input.IsActionPressed("boost")){
ApplyCentralForce(Basis.Y * fd * thrust);
if (!rocketAudioPlayer.Playing){
rocketAudioPlayer.Play();
}
} else {
rocketAudioPlayer.Stop();
}
if (Input.IsActionPressed("rotate_left")){
ApplyTorque(ZLeft * fd);
@ -50,6 +57,7 @@ public partial class Player : RigidBody3D
private void CrashSequence(){
deathAudioPlayer.Play();
rocketAudioPlayer.Stop();
Tween tween = CreateTween();
tween.TweenInterval(2.5);
tween.TweenCallback(Callable.From(() => DeferredCalls.ReloadCurrentScene(this)));

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=6 format=3 uid="uid://cuduv6fwqtocs"]
[gd_scene load_steps=7 format=3 uid="uid://cuduv6fwqtocs"]
[ext_resource type="Script" path="res://scenes/characters/Player.cs" id="1_fr1bo"]
[ext_resource type="AudioStream" uid="uid://nsq05kpsix83" path="res://resources/audio/SFX - Death Explosion.ogg" id="2_ml1je"]
[ext_resource type="AudioStream" uid="uid://cr4ckjeqxa5xe" path="res://resources/audio/SFX - Success.ogg" id="3_xmihe"]
[ext_resource type="AudioStream" uid="uid://dyf7x2qy7lww" path="res://resources/audio/SFX - Main engine thrust.ogg" id="4_204bm"]
[sub_resource type="CylinderMesh" id="CylinderMesh_dk8lw"]
@ -29,3 +30,6 @@ stream = ExtResource("2_ml1je")
[node name="SuccessAudioPlayer" type="AudioStreamPlayer" parent="."]
stream = ExtResource("3_xmihe")
[node name="RocketAudioPlayer" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource("4_204bm")