Use fire stick magnitude for aim distance

This commit is contained in:
Loïc Wisniewski 2026-09-01 23:50:05 +02:00
commit 7892a162f3
2 changed files with 27 additions and 10 deletions

View file

@ -3,9 +3,10 @@ extends Node2D
# Points every armed vessel's gun wherever the right-hand stick is pushed.
#
# #172: what it points them at is a PLACE, not a heading. The mouse names one
# directly; a pushed stick names the one at the guns' reach along it. Each hull
# then works out its own heading to that place, so the fleet's fire converges
# there instead of leaving in parallel - see VesselWeaponComponent.
# directly; a pushed stick names a point along it, with the push magnitude
# choosing the distance from the fleet up to the guns' reach. Each hull then
# works out its own heading to that place, so the fleet's fire converges there
# instead of leaving in parallel - see VesselWeaponComponent.
#
# The fleet's guns used to seek their own targets and fire on their own. That
# made combat something that happened TO the player rather than something they
@ -76,14 +77,14 @@ func _process(_delta: float) -> void:
queue_redraw()
# #172: a stick reports a heading, and the guns want a place. The place is at
# the guns' own reach along that heading - far enough out that a pushed stick
# still reads as "everything that way", and near enough that the fleet's fire
# meets rather than spreading for ever.
# #172 made the stick resolve to a point so fleet fire converges. The stick
# already reports both direction and a 0..1 displacement; preserve that second
# value so a phone player can pull the convergence point nearer or push it all
# the way to the guns' reach.
func stick_point(direction: Vector2) -> Vector2:
if fleet == null or direction == Vector2.ZERO:
return Vector2.ZERO
return fleet.get_centroid() + direction.normalized() * maxf(guide_range(), 1.0)
return fleet.get_centroid() + direction.limit_length(1.0) * maxf(guide_range(), 1.0)
# Also the entry point for anything driving the guns without a stick - tests