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:
parent
a902fddba0
commit
2239235993
5 changed files with 123 additions and 28 deletions
|
|
@ -8,6 +8,17 @@ const COMBAT_TARGET = preload("res://core/CombatTarget.gd")
|
|||
# shot effect, and effect visuals.
|
||||
|
||||
const AIM_DEADZONE: float = 22.0
|
||||
# The aim view eases to its framing instead of cutting to it, in both
|
||||
# directions. A hard jump loses where everything just went - the more so now
|
||||
# that aiming can travel a long way - and the eye cannot follow a cut it did
|
||||
# not make. Fast, though: this happens under a thumb that is already aiming,
|
||||
# so it settles in about a quarter of a second rather than gliding.
|
||||
const ZOOM_EASE_SPEED: float = 12.0
|
||||
# A floor under that rate, as a multiple of the zoom being approached. A purely
|
||||
# proportional ease slows as it closes and never actually arrives, which would
|
||||
# leave "has the camera restored" false forever and let the next aim record a
|
||||
# resting zoom that is still moving.
|
||||
const ZOOM_MIN_RATE: float = 4.0
|
||||
|
||||
@export var minimum_zoom: float = 0.4
|
||||
@onready var fleet: Node2D = get_node("../Fleet")
|
||||
|
|
@ -22,6 +33,9 @@ var aim_start_screen: Vector2 = Vector2.ZERO
|
|||
var aim_screen: Vector2 = Vector2.ZERO
|
||||
var aim_target: Vector2 = Vector2.ZERO
|
||||
var saved_zoom: float = 1.0
|
||||
# What the aim wants to be framed at. Written by _update_aim_zoom(); the
|
||||
# camera walks toward it in _process() rather than being assigned it.
|
||||
var desired_zoom: float = 1.0
|
||||
var restoring_zoom: bool = false
|
||||
|
||||
|
||||
|
|
@ -45,11 +59,11 @@ func _process(delta: float) -> void:
|
|||
if status.text != "" and Time.get_ticks_msec() >= status_message_until:
|
||||
status.text = ""
|
||||
|
||||
if restoring_zoom and not aiming:
|
||||
var zoom: float = move_toward(camera.zoom.x, saved_zoom,
|
||||
maxf(saved_zoom, 0.1) * delta * 5.0)
|
||||
camera.zoom = Vector2(zoom, zoom)
|
||||
if is_equal_approx(zoom, saved_zoom):
|
||||
if aiming:
|
||||
_ease_zoom(desired_zoom, delta)
|
||||
elif restoring_zoom:
|
||||
_ease_zoom(saved_zoom, delta)
|
||||
if is_equal_approx(camera.zoom.x, saved_zoom):
|
||||
restoring_zoom = false
|
||||
|
||||
_advance_effects(delta)
|
||||
|
|
@ -77,6 +91,7 @@ func fire_at(world_target: Vector2) -> bool:
|
|||
# Recorded before firing because _fire() ends by restoring it, and a stale
|
||||
# value from an earlier aim would snap the camera somewhere unrelated.
|
||||
saved_zoom = camera.zoom.x
|
||||
desired_zoom = saved_zoom
|
||||
restoring_zoom = false
|
||||
aim_target = world_target
|
||||
_fire()
|
||||
|
|
@ -96,6 +111,7 @@ func handle_touch(event: InputEventScreenTouch) -> bool:
|
|||
aim_start_screen = event.position
|
||||
aim_screen = event.position
|
||||
saved_zoom = camera.zoom.x
|
||||
desired_zoom = saved_zoom
|
||||
restoring_zoom = false
|
||||
button.pressed_down = true
|
||||
button.queue_redraw()
|
||||
|
|
@ -165,9 +181,18 @@ func _update_aim_zoom(origin: Vector2, target: Vector2) -> void:
|
|||
else half_screen.x / (absf(displacement.x) + padding)
|
||||
var fit_y: float = saved_zoom if absf(displacement.y) < 1.0 \
|
||||
else half_screen.y / (absf(displacement.y) + padding)
|
||||
var desired: float = clampf(minf(saved_zoom, minf(fit_x, fit_y)),
|
||||
desired_zoom = clampf(minf(saved_zoom, minf(fit_x, fit_y)),
|
||||
minimum_zoom, saved_zoom)
|
||||
camera.zoom = Vector2(desired, desired)
|
||||
|
||||
|
||||
# Proportional rather than a fixed step per second, so the same easing reads
|
||||
# the same whether the camera is crossing from 2.5 to 0.15 or barely moving,
|
||||
# with the floor above closing the last of it exactly.
|
||||
func _ease_zoom(target: float, delta: float) -> void:
|
||||
var step: float = maxf(absf(target - camera.zoom.x) * ZOOM_EASE_SPEED,
|
||||
maxf(target, 0.1) * ZOOM_MIN_RATE) * delta
|
||||
var zoom: float = move_toward(camera.zoom.x, target, step)
|
||||
camera.zoom = Vector2(zoom, zoom)
|
||||
|
||||
|
||||
func _finish_aim() -> void:
|
||||
|
|
|
|||
Loading…
Reference in a new issue