func get_nearest_node():
var array = get_tree().get_nodes_in_group("team_a")
#This code gets the nodes in the "team_a" group to an Array
var player_in_team = [ [array[0].position.distance_to(player.position),array[0]] , [array[1].position.distance_to(player.position),array[1]] , [array[2].position.distance_to(player.position),array[2]] ]
#This code takes the distances of all the objects in the group to the player and makes it a new array
player_in_team.sort_custom(func(a,b): return a[0] < b[0])
#This code sorts the distance codes to the player in the array we just made, from smallest to largest.
return player_in_team[0][1]
#This code returns the name of the nearest node
So you can use this function like that:
look_at(get_nearest_node().position)
You can improve this code , whatever you like and make it even better. This is just the simpliest code to teach beginners
You are welcome!
Better Look: