Advanced: good 2D audio architecture

Yes, you attach the RemoteTransform2D to the enemy/bullet and set the RemoteTransform2D.remote_path to the path to the AudioStreamPlayer2D relative to the RemoteTransform2D with Node.get_path_to()

For example:

func play_and_follow(stream:AudioStream, remote_transform:RemoteTransform2D, start_time:float = 0.0, volume_db:float = 0.0, pitch_scale:float = 1.0) -> void:
	var player = AudioStreamPlayer2D.new()
	add_child(player)

	if is_instance_valid(remote_transform):
		remote_transform.remote_path = remote_transform.get_path_to(player)

	player.stream = stream
	player.volume_db = volume_db
	player.pitch_scale = pitch_scale

	player.play(start_time)
2 Likes