1
0
Fork 0
spacetac/tac/units/fighter.gd

16 lines
475 B
GDScript3
Raw Normal View History

2022-10-06 22:34:33 +00:00
extends Unit
2022-10-10 03:01:02 +00:00
func tick():
2022-10-06 22:34:33 +00:00
# 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:
2022-10-10 03:01:02 +00:00
move_to(enemy.global_position + Vector2.from_angle(randf_range(0.0, PI * 2.0)) * randf_range(100.0, 300.0))
2022-10-06 22:34:33 +00:00
$turret.set_target(enemy)