Gate enemies behind a detection range instead of instant omniscient pursuit (#69)
Chasers (EnemyPursuitComponent) and snipers (EnemyStandoffComponent) used to beeline/close in from anywhere on the map the instant they spawned - no matter how far the fleet was, which read as omniscient rather than alert. Both now sit idle until the fleet is within their own detection_range. Artillery's slow drift is gated the same way, but reuses its own existing fire_range rather than a new tunable - outside its firing envelope it has nothing to be drifting toward yet. The enemy mothership deliberately keeps the opposite behaviour: it is meant to read as a persistent, unavoidable stalking threat, not a local sentry, so it gets its own EnemyPursuitComponentMothership.tscn variant with an effectively unlimited detection_range - the same scene-variant pattern EnemySpawnerComponentChaser/Artillery already use for per-definition property overrides on a shared component script.
This commit is contained in:
parent
8d089d6f76
commit
1de66c6fb2
6 changed files with 161 additions and 7 deletions
|
|
@ -7,11 +7,20 @@ extends Node
|
|||
var capability_id: String = "pursuit"
|
||||
var velocity: Vector2 = Vector2.ZERO
|
||||
|
||||
# #69: used to beeline from anywhere on the map the instant it spawned,
|
||||
# which read as omniscient rather than alert. Idle until the fleet actually
|
||||
# comes within this radius. A persistent stalking threat wants the opposite
|
||||
# of this - see EnemyPursuitComponentMothership.tscn, which overrides it to
|
||||
# an effectively unlimited value for the mothership's own instance.
|
||||
@export var detection_range: float = 850.0
|
||||
|
||||
|
||||
func tick(delta: float) -> void:
|
||||
var enemy: Node2D = get_parent()
|
||||
var target_pos: Vector2 = _nearest_ship_position(enemy)
|
||||
var to_target: Vector2 = target_pos - enemy.position
|
||||
var target: Node2D = _nearest_ship(enemy)
|
||||
if target == null or enemy.position.distance_to(target.position) > detection_range:
|
||||
return
|
||||
var to_target: Vector2 = target.position - enemy.position
|
||||
|
||||
if to_target.length() > 1.0:
|
||||
var desired_velocity: Vector2 = to_target.normalized() * enemy.speed
|
||||
|
|
@ -23,10 +32,10 @@ func tick(delta: float) -> void:
|
|||
enemy.rotation = lerp_angle(enemy.rotation, target_angle, enemy.rotation_speed * delta)
|
||||
|
||||
|
||||
func _nearest_ship_position(enemy: Node2D) -> Vector2:
|
||||
func _nearest_ship(enemy: Node2D) -> Node2D:
|
||||
var fleet: Node2D = get_tree().get_first_node_in_group("player_fleet")
|
||||
if fleet == null or fleet.ships.is_empty():
|
||||
return enemy.position
|
||||
return null
|
||||
|
||||
var nearest: Node2D = fleet.ships[0]
|
||||
var best_dist: float = enemy.position.distance_to(nearest.position)
|
||||
|
|
@ -35,4 +44,4 @@ func _nearest_ship_position(enemy: Node2D) -> Vector2:
|
|||
if d < best_dist:
|
||||
best_dist = d
|
||||
nearest = ship
|
||||
return nearest.position
|
||||
return nearest
|
||||
|
|
|
|||
Loading…
Reference in a new issue