Aim the laser by depth, and ease the aim view

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019AJMdB7iuHuLFZM1aBu3GD
This commit is contained in:
Loïc Wisniewski 2026-09-05 09:32:42 +02:00
commit 2239235993
5 changed files with 123 additions and 28 deletions

View file

@ -19,6 +19,14 @@ const TARGET_COLOR := Color(0.6, 0.95, 1.0)
# #203's range mark and the assist's target ring, in screen pixels.
const END_TICK_PIXELS: float = 17.0
const TARGET_RING_PIXELS: float = 15.0
# How far the thumb travels to walk the aim point out to the beam's full
# reach. The same idiom the gas bomb uses for its throw distance.
const DRAG_RADIUS: float = 260.0
# The aim view frames twice the distance to the chosen target, so there is as
# much space beyond it as in front of it. Framing the target itself would put
# it on the edge of the screen, which is the half that matters when the point
# of dragging further is to reach past what is already close.
const FRAMING_FACTOR: float = 2.0
const BEAM_HALF_WIDTH := BEAM_EFFECT.BEAM_HALF_WIDTH
const FLASH_DURATION := BEAM_EFFECT.FLASH_DURATION
const ENERGY_PER_SHOT: int = VesselLaserComponent.ENERGY_PER_SHOT
@ -55,9 +63,15 @@ func _aim_max_range() -> float:
func _calculate_aim_target(drag: Vector2, origin: Vector2) -> Vector2:
# A beam always reaches full range; dragging chooses its direction only.
# The shot always reaches full range; the drag chooses a direction AND a
# depth along it. Depth is what lets the helper reach a target standing
# behind a nearer one: the assist looks for something near the point the
# thumb actually named, and only falls back to the nearest thing in the
# cone when the player has named no place in particular.
var direction: Vector2 = drag.normalized() if drag.length() > 0.001 else Vector2.UP
return _assisted_target(origin, origin + direction * _aim_max_range())
var reach: float = _aim_max_range()
var depth: float = minf(drag.length() / DRAG_RADIUS, 1.0) * reach
return _assisted_target(origin, origin + direction * maxf(depth, 1.0))
# The mouse path (#80) names a world point directly instead of dragging one
@ -117,14 +131,13 @@ func beam_tip(beam: Node2D) -> Vector2:
return beam.tip()
# #203: the aim view frames the beam's WHOLE reach, not the point the aim
# happens to sit on. The assist can settle that point on an enemy a few
# hundred units away (#201), and fitting the camera to it would say the shot
# stops there. Fitting the far end instead is also what makes the range
# visible at all: the beam is 2900 units long and the inherited floor on the
# zoom - sized for the gas bomb's 950 - left three quarters of it off screen.
# #203: framed around the chosen target rather than around the fleet. The
# inherited floor on the zoom was sized for the gas bomb's 950 units and left
# most of a 2900-unit aim off screen; the laser's own floor lets this fit.
# Twice the target's distance, so what lies beyond it is on screen too - that
# is the half the player is reaching into when they drag further out.
func _update_aim_zoom(origin: Vector2, target: Vector2) -> void:
super(origin, origin + _aim_heading(origin, target) * _aim_max_range())
super(origin, origin + (target - origin) * FRAMING_FACTOR)
func _aim_heading(origin: Vector2, target: Vector2) -> Vector2: