Use fire stick magnitude for aim distance
This commit is contained in:
parent
eb1615ab6b
commit
7892a162f3
2 changed files with 27 additions and 10 deletions
|
|
@ -3,9 +3,10 @@ extends Node2D
|
||||||
# Points every armed vessel's gun wherever the right-hand stick is pushed.
|
# 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
|
# #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
|
# directly; a pushed stick names a point along it, with the push magnitude
|
||||||
# then works out its own heading to that place, so the fleet's fire converges
|
# choosing the distance from the fleet up to the guns' reach. Each hull then
|
||||||
# there instead of leaving in parallel - see VesselWeaponComponent.
|
# 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
|
# 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
|
# made combat something that happened TO the player rather than something they
|
||||||
|
|
@ -76,14 +77,14 @@ func _process(_delta: float) -> void:
|
||||||
queue_redraw()
|
queue_redraw()
|
||||||
|
|
||||||
|
|
||||||
# #172: a stick reports a heading, and the guns want a place. The place is at
|
# #172 made the stick resolve to a point so fleet fire converges. The stick
|
||||||
# the guns' own reach along that heading - far enough out that a pushed stick
|
# already reports both direction and a 0..1 displacement; preserve that second
|
||||||
# still reads as "everything that way", and near enough that the fleet's fire
|
# value so a phone player can pull the convergence point nearer or push it all
|
||||||
# meets rather than spreading for ever.
|
# the way to the guns' reach.
|
||||||
func stick_point(direction: Vector2) -> Vector2:
|
func stick_point(direction: Vector2) -> Vector2:
|
||||||
if fleet == null or direction == Vector2.ZERO:
|
if fleet == null or direction == Vector2.ZERO:
|
||||||
return 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
|
# Also the entry point for anything driving the guns without a stick - tests
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,8 @@ extends SceneTree
|
||||||
# heading - and each one's line actually arrives at the point
|
# heading - and each one's line actually arrives at the point
|
||||||
# B. the mouse hands over a place: the cursor's world position, distance
|
# B. the mouse hands over a place: the cursor's world position, distance
|
||||||
# included, rather than a bearing from the fleet's centre
|
# included, rather than a bearing from the fleet's centre
|
||||||
# C. a pushed stick still works, resolving to the point at the guns' reach
|
# C. stick displacement controls convergence distance: a partial push aims
|
||||||
# along it - the touch player loses nothing
|
# nearby and a full push reaches the guns' maximum range
|
||||||
# D. the assist (#89) still bends a shot onto an enemy, now per hull and
|
# D. the assist (#89) still bends a shot onto an enemy, now per hull and
|
||||||
# around each hull's own heading to the point
|
# around each hull's own heading to the point
|
||||||
# E. releasing stops every gun in the fleet
|
# E. releasing stops every gun in the fleet
|
||||||
|
|
@ -173,6 +173,22 @@ func _process(delta: float) -> bool:
|
||||||
return _fail("a pushed stick aimed a hull somewhere other than the point it names")
|
return _fail("a pushed stick aimed a hull somewhere other than the point it names")
|
||||||
print("a pushed stick names the point at the guns' reach (%.0f) along it" % reach)
|
print("a pushed stick names the point at the guns' reach (%.0f) along it" % reach)
|
||||||
|
|
||||||
|
# A half push must keep its magnitude. TouchJoystick already reports
|
||||||
|
# displacement in the 0..1 range; normalizing it here used to turn
|
||||||
|
# every nonzero push into a maximum-range aim.
|
||||||
|
var partial := Vector2(0.0, -0.45)
|
||||||
|
var partial_point: Vector2 = controller.stick_point(partial)
|
||||||
|
var partial_wanted: Vector2 = fleet.get_centroid() + partial * reach
|
||||||
|
if partial_point.distance_to(partial_wanted) > 1.0:
|
||||||
|
return _fail("a 45%% stick push resolved to %s, expected nearby point %s" \
|
||||||
|
% [partial_point, partial_wanted])
|
||||||
|
controller.aim(partial)
|
||||||
|
for ship in [left_ship, right_ship]:
|
||||||
|
if _weapon(ship).fire_target.distance_to(partial_wanted) > 1.0:
|
||||||
|
return _fail("a partial stick push did not aim the fleet at its nearer point")
|
||||||
|
print("a 45%% stick push aims at 45%% range (%.0f), not maximum range" \
|
||||||
|
% fleet.get_centroid().distance_to(partial_point))
|
||||||
|
|
||||||
# --- F. reach is the gun's, not the aim's -------------------
|
# --- F. reach is the gun's, not the aim's -------------------
|
||||||
var far_point: Vector2 = fleet.get_centroid() + Vector2(0.0, -reach * 3.0)
|
var far_point: Vector2 = fleet.get_centroid() + Vector2(0.0, -reach * 3.0)
|
||||||
controller.aim_at(far_point)
|
controller.aim_at(far_point)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue