16 lines
407 B
GDScript3
16 lines
407 B
GDScript3
|
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)
|