Footsteps.

This commit is contained in:
unfa 2020-09-18 00:33:51 +02:00
parent ae28e5d254
commit 68f54b503a
4 changed files with 49 additions and 1 deletions

View file

@ -11,5 +11,6 @@ script = ExtResource( 2 )
[node name="SoundShoot" type="AudioStreamPlayer3D" parent="."]
stream = ExtResource( 3 )
unit_db = -12.0
[editable path="Handgun"]

View file

@ -17,6 +17,16 @@ onready var health = max_health
onready var camera = $Camera
onready var debug = $Debug
onready var sfx_foosteps = [$"Sounds/Footstep-Concrete-01",
$"Sounds/Footstep-Concrete-02",
$"Sounds/Footstep-Concrete-03",
$"Sounds/Footstep-Concrete-04"]
var sfx_footsteps_last = 0
var sfx_footsteps_next = 0
var sfx_footsteps_delay = 0.2
var sfx_footsteps_play = false
onready var game = get_parent().get_parent()
var velocity = Vector3.ZERO
@ -30,6 +40,17 @@ var bulletHitEffect = preload("res://Assets/Effects/BulletHit.tscn")
# var a = 2
# var b = "text"
func sfx_play_footsteps():
if not sfx_footsteps_play:
sfx_footsteps_play = true
while sfx_footsteps_next == sfx_footsteps_last:
sfx_footsteps_next = randi() % len(sfx_foosteps)
sfx_footsteps_last = sfx_footsteps_next
print("Play footstep: ", String(sfx_footsteps_next) )
sfx_foosteps[sfx_footsteps_next].play()
yield(get_tree().create_timer(sfx_footsteps_delay),"timeout")
sfx_footsteps_play = false
func gravity():
if not is_on_floor():
self.velocity.y -= GRAVITY
@ -62,6 +83,9 @@ remote func walk(direction: Vector2):
velocity.x = lerp(velocity.x, walkVelocity.rotated(- self.rotation.y).y, interpolation)
velocity.z = lerp(velocity.z, - walkVelocity.rotated(- self.rotation.y).x, interpolation)
if walkVelocity.length() > 0 and is_on_floor():
sfx_play_footsteps()
remote func jump():
if is_on_floor():
velocity.y = JUMP_VELOCITY

View file

@ -1,7 +1,11 @@
[gd_scene load_steps=6 format=2]
[gd_scene load_steps=10 format=2]
[ext_resource path="res://Player.gd" type="Script" id=1]
[ext_resource path="res://Assets/Weapons/Handgun/Handgun.tscn" type="PackedScene" id=2]
[ext_resource path="res://Assets/SFX/Player-Step-Concrete-01.wav" type="AudioStream" id=3]
[ext_resource path="res://Assets/SFX/Player-Step-Concrete-02.wav" type="AudioStream" id=4]
[ext_resource path="res://Assets/SFX/Player-Step-Concrete-04.wav" type="AudioStream" id=5]
[ext_resource path="res://Assets/SFX/Player-Step-Concrete-03.wav" type="AudioStream" id=6]
[sub_resource type="CapsuleShape" id=1]
radius = 0.33
@ -48,6 +52,20 @@ __meta__ = {
"_edit_use_anchors_": false
}
[node name="Sounds" type="Spatial" parent="."]
[node name="Footstep-Concrete-01" type="AudioStreamPlayer3D" parent="Sounds"]
stream = ExtResource( 3 )
[node name="Footstep-Concrete-02" type="AudioStreamPlayer3D" parent="Sounds"]
stream = ExtResource( 4 )
[node name="Footstep-Concrete-03" type="AudioStreamPlayer3D" parent="Sounds"]
stream = ExtResource( 6 )
[node name="Footstep-Concrete-04" type="AudioStreamPlayer3D" parent="Sounds"]
stream = ExtResource( 5 )
[node name="CrosshairContainer" type="CenterContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5

View file

@ -22,6 +22,11 @@ https://github.com/unfa/liblast"
run/main_scene="res://Game.tscn"
config/icon="res://icon.png"
[audio]
enable_audio_input=true
mix_rate=48000
[input]
MoveForward={