Files
tidewall/src/client/aim_assist.gd
T
claudeandClaude Opus 5.5 8142e39ab3 A13: Gamepad and accessibility
Gamepad: PadInput reads pad events in one fixed layout (sticks move and
look, triggers aim and fire, bumpers step slots and build pieces, Start
pauses), fed through ClientInput alongside the keys and mouse. Menus take
South to choose and East or Start to go back. The tutorial names pad
buttons once the pad is used.

Aim assist (option, on by default, pad only): friction across an
opponent in plain sight near the look, and a pull of at most 9 deg/s
while aiming. Client look only; never through cover.

Accessibility (new Access tab): colour-vision sets for the signal colours
(red-green, blue-yellow), checked by simulated colour vision in
test_palette; interface size 90-130%, with the HUD hotbar refitting at the
larger sizes; captions for key sounds with direction; reduce motion
(calmer aim zoom and hurt flash).

Tests for the pad, aim assist, captions, palettes, settings, the menus
driven from a pad, and a pad playing through a real offline session.
make access-captures renders the new screens and options.

Closes #53

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 08:53:30 -05:00

69 lines
3.1 KiB
GDScript

## Aim assist for the gamepad (A13), an option, on by default, and never applied to the
## mouse. Two gentle effects, both only for an opponent in plain sight close to where
## the player is already looking:
##
## - Friction: the right stick turns more slowly across an opponent, so a stick can
## settle on them instead of sliding past.
## - Pull: while aiming down sights and moving (the stick or the player), the look
## eases towards the opponent's chest, by no more than PULL_RADIANS_PER_SECOND.
##
## It only turns the client's look, the same as a player's own thumb, so it changes
## nothing the server judges. It never aims through cover: `clear` decides what is
## in sight, and the session passes the world's own line test.
class_name AimAssist
extends RefCounted
## How far either side of the look an opponent can be and still count.
const CONE_RADIANS: float = deg_to_rad(6.0)
## Further than this, nobody counts.
const RANGE_METRES: float = 90.0
## Look speed at the very centre of an opponent, against 1 away from them.
const FRICTION: float = 0.45
## The fastest the pull turns the look.
const PULL_RADIANS_PER_SECOND: float = deg_to_rad(9.0)
## The opponent nearest the look within the cone: {"point", "angle"}, or {} for none.
## `clear` takes (eye, point) and returns true when nothing is between them.
static func nearest(eye: Vector3, yaw: float, pitch: float, targets: Array[Vector3], clear: Callable = Callable()) -> Dictionary:
var look: Vector3 = CameraRig.look_direction(yaw, pitch)
var best: Dictionary = {}
var best_angle: float = CONE_RADIANS
for point: Vector3 in targets:
var to: Vector3 = point - eye
var distance: float = to.length()
if distance < 0.5 or distance > RANGE_METRES:
continue
var angle: float = look.angle_to(to / distance)
if angle >= best_angle:
continue
if clear.is_valid() and not bool(clear.call(eye, point)):
continue
best_angle = angle
best = {"point": point, "angle": angle}
return best
## How much the stick's turn is slowed: 1 with nobody near the look, down to FRICTION
## at an opponent's centre.
static func friction(found: Dictionary) -> float:
if found.is_empty():
return 1.0
return lerpf(FRICTION, 1.0, clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0))
## The look after `delta` seconds of pull towards `found`: Vector2(yaw, pitch). Pulls
## harder the closer the look already is, and never past the opponent.
static func pull(eye: Vector3, yaw: float, pitch: float, found: Dictionary, delta: float) -> Vector2:
if found.is_empty():
return Vector2(yaw, pitch)
var to: Vector3 = Vector3(found["point"]) - eye
var want_yaw: float = atan2(to.x, to.z)
var want_pitch: float = atan2(to.y, Vector2(to.x, to.z).length())
var turn: Vector2 = Vector2(angle_difference(yaw, want_yaw), want_pitch - pitch)
var closeness: float = 1.0 - clampf(float(found["angle"]) / CONE_RADIANS, 0.0, 1.0)
var step: float = PULL_RADIANS_PER_SECOND * closeness * delta
if turn.length() > step:
turn = turn.normalized() * step
return Vector2(fposmod(yaw + turn.x, TAU), clampf(pitch + turn.y, -InputSettings.PITCH_LIMIT, InputSettings.PITCH_LIMIT))