grunk/src/world/game_sound/game_sound_emitter.gd

35 lines
939 B
GDScript3
Raw Normal View History

@tool
class_name GameSoundEmitter extends Area3D
## Sends an alert to any intersecting GameSoundListener on command
func _set_collision() -> void:
collision_layer = 0
collision_mask = GameSoundListener.SOUND_COLLISION_LAYER
func _ready() -> void:
_set_collision()
func _process(_delta: float) -> void:
if Engine.is_editor_hint():
_set_collision()
## Trigger a sound detection event on all GameSoundListeners in range.
##
## The source of the sound will be the global position of this emitter.
func emit_sound_here() -> void:
emit_sound(global_position)
## Trigger a sound detection event on all GameSoundListeners in range.
##
## `source` is the global position of the source of the sound.
func emit_sound(source: Vector3) -> void:
print_debug(self, " emitted game sound at ", source)
for body: Node3D in self.get_overlapping_bodies():
if body is GameSoundListener:
(body as GameSoundListener).detect_sound(source)