From 3520bfbe66e369bf70f88e76b8e13f111448d96e Mon Sep 17 00:00:00 2001 From: unfa Date: Sun, 12 Sep 2021 04:28:38 +0200 Subject: [PATCH] Added shell casings sound. --- Game/Assets/Audio/SoundPlayer.gd | 2 +- Game/Assets/Weapons/Handgun/Casing.gd | 12 ++++++++++++ Game/Assets/Weapons/Handgun/Casing.tscn | 21 +++++++++++++++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/Game/Assets/Audio/SoundPlayer.gd b/Game/Assets/Audio/SoundPlayer.gd index 3fe3411..58d226e 100644 --- a/Game/Assets/Audio/SoundPlayer.gd +++ b/Game/Assets/Audio/SoundPlayer.gd @@ -18,7 +18,7 @@ var ready_to_play = true # used as a semaphor for MinDelay var voices = [] var voice = 0 -var debug = true +var debug = false func _ready(): var files = [] diff --git a/Game/Assets/Weapons/Handgun/Casing.gd b/Game/Assets/Weapons/Handgun/Casing.gd index d8990b7..b7d09de 100644 --- a/Game/Assets/Weapons/Handgun/Casing.gd +++ b/Game/Assets/Weapons/Handgun/Casing.gd @@ -1,5 +1,7 @@ extends RigidBody3D +@onready var sound = $Sound +@onready var sound_player = sound.get_node("AudioStreamPlayer3D") # Declare member variables here. Examples: # var a = 2 @@ -19,3 +21,13 @@ func _ready(): func _on_Timer_timeout(): queue_free() + + +func _on_Casing_body_entered(body): + var vel = linear_velocity.length() + print(linear_velocity.length()) + + if vel > 0.25: + sound_player.unit_db = -48 + min((pow(vel, 3)), 48) + + sound.play() diff --git a/Game/Assets/Weapons/Handgun/Casing.tscn b/Game/Assets/Weapons/Handgun/Casing.tscn index 36e71a3..94b0023 100644 --- a/Game/Assets/Weapons/Handgun/Casing.tscn +++ b/Game/Assets/Weapons/Handgun/Casing.tscn @@ -1,11 +1,12 @@ -[gd_scene load_steps=5 format=3 uid="uid://dfwe3bvh8lbbp"] +[gd_scene load_steps=6 format=3 uid="uid://dfwe3bvh8lbbp"] [ext_resource type="PackedScene" uid="uid://b6aa41e8u5cxi" path="res://Assets/Weapons/Handgun/Casing.gltf" id="1"] [ext_resource type="Script" path="res://Assets/Weapons/Handgun/Casing.gd" id="1_kwgjj"] +[ext_resource type="PackedScene" uid="uid://c5cwnfuw4go1b" path="res://Assets/Audio/SoundPlayer.tscn" id="3_47hc3"] [sub_resource type="PhysicsMaterial" id="1"] friction = 0.7 -bounce = 0.2 +bounce = 0.7 [sub_resource type="CylinderShape3D" id="2"] radius = 0.0119513 @@ -17,6 +18,8 @@ collision_mask = 9 mass = 0.01 physics_material_override = SubResource( "1" ) continuous_cd = true +contacts_reported = 1 +contact_monitor = true script = ExtResource( "1_kwgjj" ) [node name="CollisionShape3D" type="CollisionShape3D" parent="."] @@ -32,4 +35,18 @@ one_shot = true autostart = true script = null +[node name="Sound" parent="." instance=ExtResource( "3_47hc3" )] +SoundClip = "res://Assets/SFX/Weapons_Handgun_Casing_01.wav" +PitchScale = 1.2 +RandomizePitch = 0.01 + +[node name="AudioStreamPlayer3D" parent="Sound" index="0"] +unit_db = -12.0 +unit_size = 2.0 +max_db = -3.0 +pitch_scale = 1.5 + +[connection signal="body_entered" from="." to="." method="_on_Casing_body_entered"] [connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"] + +[editable path="Sound"]