extends Area2D

var entities

func getCloserEnemy():
	entities = get_overlapping_bodies()
	var minDist = 9999
	var closerEnemy
	var dist
	for enemy in entities:
		if enemy.is_in_group("EnemyGroup"):
			dist = position.distance_to(enemy.position)
			if dist <  minDist:
				minDist = dist
				closerEnemy = enemy
	return closerEnemy

func getClosestPlayer():
	entities = get_tree().get_nodes_in_group("PlayerGroup")
	var minDist = 9999
	var closerPlayer
	var dist
	for enemy in entities:
		dist = global_position.distance_to(enemy.global_position)
		if dist <  minDist:
			minDist = dist
			closerPlayer = enemy
	return closerPlayer