diff options
author | jacopograndi <jacopo.grandi@outlook.it> | 2022-02-01 15:19:36 +0100 |
---|---|---|
committer | jacopograndi <jacopo.grandi@outlook.it> | 2022-02-01 15:19:36 +0100 |
commit | e8b2ea6b2bf789b7942d86faebbcc4d810741f25 (patch) | |
tree | 042004ea555859cd33c3069f88593a35f5e09a3c /scripts/turret.gd | |
parent | ff51a1e6f7bfa7e005a6894cd22e7bce4971b963 (diff) |
targeting
Diffstat (limited to 'scripts/turret.gd')
-rw-r--r-- | scripts/turret.gd | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/scripts/turret.gd b/scripts/turret.gd index 32fb17a..62c9f6f 100644 --- a/scripts/turret.gd +++ b/scripts/turret.gd @@ -126,6 +126,39 @@ func filter_visible(set): if hit == node: filtered += [ target ] return filtered + +func targeting (set, aim): + var pick = set[0] + var pick_val = value(pick, aim) + for target in set: + var enemy = _enemies.enemies[target] + var d = value(target, aim) + if d > pick_val: + pick_val = d + pick = target + return pick + +func value(a, aim): + var enemy = _enemies.enemies[a] + match aim: + "first": return enemy.cur+enemy.rel + "last": return - (enemy.cur+enemy.rel) + "strongest": return enemy.hp + "weakest": return -enemy.hp + "closest": + var node = _enemies.node_from_id(a) + return - _shooting_point.distance_squared_to(node.transform.origin) + "furthest": + var node = _enemies.node_from_id(a) + return _shooting_point.distance_squared_to(node.transform.origin) + "least turning": + var node = _enemies.node_from_id(a) + return node.transform.basis.z.signed_angle_to( + gun.transform.basis.z, Vector3.UP) + "most turning": + var node = _enemies.node_from_id(a) + return -node.transform.basis.z.signed_angle_to( + gun.transform.basis.z, Vector3.UP) func get_target(): var ids = [] @@ -135,7 +168,7 @@ func get_target(): set = filter_visible(set) if set.size() > 0: - return set[0] + return targeting(set, aim_mode) else: return null func _physics_process(delta): |