bugged-racing/vehicles/tire_smoke.gd

31 lines
705 B
GDScript
Raw Permalink Normal View History

2021-11-13 21:22:07 +00:00
class_name TireSmoke
extends Particles
2021-11-13 21:48:15 +00:00
onready var sound_player: AudioStreamPlayer3D = $tire_sound_player
onready var sound_playback: AudioStreamPlayback = $tire_sound_player.get_stream_playback()
2021-11-18 23:36:05 +00:00
2021-11-13 21:48:15 +00:00
func _ready() -> void:
_update_sound(1)
# sound_player.play()
2021-11-18 23:36:05 +00:00
2021-11-13 21:22:07 +00:00
func update(skidinfo: float) -> void:
2021-11-13 21:48:15 +00:00
_update_sound(skidinfo)
2021-11-13 21:22:07 +00:00
if skidinfo < 0.5:
emitting = true
else:
emitting = false
2021-11-13 21:48:15 +00:00
2021-11-18 23:36:05 +00:00
2021-11-13 21:48:15 +00:00
func _update_sound(skidinfo: float) -> void:
sound_player.pitch_scale = 1 + (1 - skidinfo)
var to_fill = sound_playback.get_frames_available()
var factor = (1 - skidinfo) * 2
if to_fill <= 0:
return
while to_fill > 0:
sound_playback.push_frame(Vector2(1.0, 1.0) * factor)
2021-11-14 21:45:47 +00:00
factor += 1
2021-11-13 21:48:15 +00:00
to_fill -= 1