W1: Third-person character controller and camera

Simulation (src/sim/):
- SimGround holds the terrain heightfield (bilinear heights, normals)
  and axis-aligned box solids, with support, body-overlap, point and
  ray queries. The island generator and building will fill it.
- Movement steps a player per tick: walk, sprint (forward only),
  crouch (lower body, slower, no jump), jump with exact constant-gravity
  integration, air control, step-up onto ledges up to STEP_HEIGHT,
  ground snapping on downhill walks, slopes over MAX_SLOPE_DEGREES that
  block walking and jumping uphill and make players slide (speed capped),
  ceiling bumps, sliding along walls, and fall damage from impact speed.
- Gravity now applies on ticks with no command. on_ground and crouching
  are part of the state hash. New movement numbers are in Tuning.
- Fixed the strafe direction: right is forward x up in Godot's frame,
  (-cos yaw, 0, sin yaw). Documented the look convention.

Client (src/client/):
- CameraRig places an over-the-shoulder camera with an eased
  aim-down-sights blend (closer, narrower FOV), casting against the same
  SimGround: pivot to shoulder, shoulder back, then a straight line from
  the pivot, with a final clearance pull-in so the near plane never
  enters geometry.
- InputSettings: mouse sensitivity, aim sensitivity scale and invert-Y,
  clamped and saved to user://settings.cfg. PlayerCamera applies both.

Tests: 46 new across movement, ground queries, camera and settings,
including a 24,480-view scripted camera sweep through five arenas (wall,
corridor, low roof, corner, steep bank) that checks the eye and every
near-plane corner stay out of geometry with a clear line to the pivot.
The hash test now flips a high stick bit, because a 1/127 nudge to an
airborne player moves them less than the hash's millimetre.
Capture scenarios camera, camera_wall and camera_aim.

Closes #8

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-09 20:24:02 -05:00
co-authored by Claude Opus 5.5
parent 68635d5fba
commit 70e88cec8a
29 changed files with 1213 additions and 23 deletions
+60
View File
@@ -0,0 +1,60 @@
## Player-adjustable look settings, saved in the user's config file.
class_name InputSettings
extends RefCounted
const DEFAULT_PATH: String = "user://settings.cfg"
const SECTION: String = "input"
## Radians of turn per pixel of mouse motion at sensitivity 1.0.
const RADIANS_PER_PIXEL: float = 0.0025
const MIN_SENSITIVITY: float = 0.05
const MAX_SENSITIVITY: float = 10.0
## Looking straight up or down flips the camera basis, so stop just short.
const PITCH_LIMIT: float = deg_to_rad(85.0)
var mouse_sensitivity: float = 1.0:
set(value):
mouse_sensitivity = clampf(value, MIN_SENSITIVITY, MAX_SENSITIVITY)
## Multiplies the sensitivity while aiming down sights.
var aim_sensitivity_scale: float = 0.6:
set(value):
aim_sensitivity_scale = clampf(value, 0.1, 2.0)
var invert_y: bool = false
## Applies a mouse motion to a look direction. Returns Vector2(yaw, pitch) in radians.
## Moving the mouse right turns right; moving it up looks up, unless invert_y is set.
func apply_mouse(relative: Vector2, yaw: float, pitch: float, aiming: bool) -> Vector2:
var scale: float = RADIANS_PER_PIXEL * mouse_sensitivity
if aiming:
scale *= aim_sensitivity_scale
var vertical: float = relative.y if invert_y else -relative.y
var new_yaw: float = fposmod(yaw - relative.x * scale, TAU)
var new_pitch: float = clampf(pitch + vertical * scale, -PITCH_LIMIT, PITCH_LIMIT)
return Vector2(new_yaw, new_pitch)
func save(path: String = DEFAULT_PATH) -> Error:
var config: ConfigFile = ConfigFile.new()
config.load(path) # Keep other sections; a missing file is fine.
config.set_value(SECTION, "mouse_sensitivity", mouse_sensitivity)
config.set_value(SECTION, "aim_sensitivity_scale", aim_sensitivity_scale)
config.set_value(SECTION, "invert_y", invert_y)
return config.save(path)
## Loads saved settings. Missing or malformed values keep their defaults.
static func load_from(path: String = DEFAULT_PATH) -> InputSettings:
var settings: InputSettings = InputSettings.new()
var config: ConfigFile = ConfigFile.new()
if config.load(path) != OK:
return settings
var sensitivity: Variant = config.get_value(SECTION, "mouse_sensitivity", 1.0)
if sensitivity is float or sensitivity is int:
settings.mouse_sensitivity = float(sensitivity)
var aim_scale: Variant = config.get_value(SECTION, "aim_sensitivity_scale", 0.6)
if aim_scale is float or aim_scale is int:
settings.aim_sensitivity_scale = float(aim_scale)
var invert: Variant = config.get_value(SECTION, "invert_y", false)
if invert is bool:
settings.invert_y = invert
return settings