Added pitch randomization and pitch scale to SoundPlayer.

remotes/1705382094874458415/tmp_refs/heads/godot4-port
unfa 2020-09-26 01:06:56 +02:00
parent 9efb1baa18
commit 56169fb5f3
3 changed files with 10 additions and 1 deletions

View File

@ -9,6 +9,7 @@ script = ExtResource( 2 )
[node name="SoundPlayer" parent="." instance=ExtResource( 1 )]
SoundClip = "res://Assets/SFX/Weapons-BulletFlyBy-01.wav"
AutoPlay = true
RandomizePitch = 0.3
[connection signal="finished" from="SoundPlayer/AudioStreamPlayer3D" to="." method="_on_AudioStreamPlayer3D_finished"]
[editable path="SoundPlayer"]

View File

@ -11,6 +11,8 @@ export(bool) var AutoPlay = false
export(float) var MinimumRandomDistance = 0.35 # gives optimal playback repetition for sound clip groups of different sizes.
export(bool) var PlayUntilEnd = false # determines if the play() function is allowed to sop a previously started sound
export(float) var MinDelay = 0 # determines how many seconds must pass before the sound can be triggered again
export(float) var PitchScale = 1
export(float) var RandomizePitch = 0
var min_distance = 0 # this determines how ofte na sound is allowed to play (any Nth time) this is calculated automatically based on maximum_repetition
var clips = [] # holds loaded sound stream resources
var recently_played = [] # holds indexes of recently played
@ -78,8 +80,13 @@ func play():
#print("recently played: ", recently_played)
player.stream = clips[i]
if RandomizePitch != 0:
player.pitch_scale = PitchScale + rand_range(-RandomizePitch /2, RandomizePitch/2)
else:
player.pitch_scale = PitchScale
player.play()
ready = false

View File

@ -61,6 +61,7 @@ SoundClip = "res://Assets/SFX/Player-Jump-01.wav"
SoundClip = "res://Assets/SFX/Player-Step-Concrete-01.wav"
PlayUntilEnd = true
MinDelay = 0.2
RandomizePitch = 0.2
[node name="Death" parent="Sounds" instance=ExtResource( 7 )]
SoundClip = "res://Assets/SFX/Player-Death-01.wav"