1
0
Fork 0
spacetac/tac/units/fighter.gd
2022-10-07 00:34:33 +02:00

16 lines
407 B
GDScript

extends Unit
func make_decision():
# go to nearest enemy
var enemy: Unit = null
var closest := INF
for unit in get_tree().get_nodes_in_group("unit"):
if unit is Unit and unit.player != player:
var distance := global_position.distance_to(unit.global_position)
if distance < closest:
closest = distance
enemy = unit
if enemy:
move_to(enemy.global_position)
$turret.set_target(enemy)