generated from krampus/template-godot4
33 lines
798 B
GDScript
33 lines
798 B
GDScript
class_name SpraySFX extends AudioStreamPlayer3D
|
|
## Plays only as long as `activate` is called every frame.
|
|
|
|
@export var base_pitch := 1.0
|
|
@export var pitch_shape_scale := 0.5
|
|
|
|
var _active_this_frame := false
|
|
|
|
@onready var spray_game_sound_emitter: GameSoundEmitter = %SprayGameSoundEmitter
|
|
|
|
|
|
func activate() -> void:
|
|
_active_this_frame = true
|
|
|
|
|
|
func set_angle_from_normal(normal: Vector3) -> void:
|
|
var to_player := Player.instance.global_position - global_position
|
|
var angle_to_player := normal.angle_to(to_player)
|
|
|
|
# linear pitch shape
|
|
pitch_scale = base_pitch - (2 * angle_to_player / PI) * pitch_shape_scale
|
|
|
|
|
|
func _process(_delta: float) -> void:
|
|
if _active_this_frame:
|
|
if not playing:
|
|
play()
|
|
spray_game_sound_emitter.emit_sound_here()
|
|
else:
|
|
stop()
|
|
|
|
_active_this_frame = false
|