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
+85
View File
@@ -0,0 +1,85 @@
extends TestCase
func _tilted() -> SimGround:
# h = 0.5 * x, a plane rising along +x.
var values: PackedFloat32Array = PackedFloat32Array()
for z: int in 4:
for x: int in 4:
values.append(0.5 * x * 2.0)
return SimGround.from_heights(values, 4, 2.0)
func test_flat_ground() -> void:
var ground: SimGround = SimGround.flat(3.0)
assert_eq(ground.terrain_height(10.0, 900.0), 3.0)
assert_true(ground.terrain_normal(10.0, 10.0).is_equal_approx(Vector3.UP))
assert_true(ground.walkable_terrain(10.0, 10.0))
func test_interpolation_and_edges() -> void:
var ground: SimGround = _tilted()
assert_near(ground.terrain_height(1.0, 1.0), 0.5, 0.0001)
assert_near(ground.terrain_height(3.0, 5.0), 1.5, 0.0001)
# Outside the grid, the edge sample is used.
assert_near(ground.terrain_height(-5.0, 2.0), 0.0, 0.0001)
assert_near(ground.terrain_height(100.0, 2.0), 3.0, 0.0001)
func test_normal_and_walkability() -> void:
var ground: SimGround = _tilted()
var normal: Vector3 = ground.terrain_normal(3.0, 3.0)
assert_near(rad_to_deg(normal.angle_to(Vector3.UP)), rad_to_deg(atan(0.5)), 0.01)
assert_true(normal.x < 0.0, "the normal leans away from the rise")
assert_true(ground.walkable_terrain(3.0, 3.0))
func test_support_from_solids() -> void:
var ground: SimGround = SimGround.flat()
ground.add_solid(AABB(Vector3(0.0, 0.0, 0.0), Vector3(2.0, 1.0, 2.0)))
ground.add_solid(AABB(Vector3(0.0, 5.0, 0.0), Vector3(2.0, 1.0, 2.0)))
assert_eq(ground.support_height(1.0, 1.0, 1.2), 1.0)
assert_eq(ground.support_height(1.0, 1.0, 10.0), 6.0)
assert_eq(ground.support_height(1.0, 1.0, 0.5), 0.0)
assert_eq(ground.support_height(3.0, 1.0, 10.0), 0.0)
assert_true(ground.support_is_solid(1.0, 1.0, 1.2))
assert_false(ground.support_is_solid(3.0, 1.0, 1.2))
func test_negative_size_solids_are_normalised() -> void:
var ground: SimGround = SimGround.flat()
ground.add_solid(AABB(Vector3(2.0, 1.0, 2.0), Vector3(-2.0, -1.0, -2.0)))
assert_eq(ground.support_height(1.0, 1.0, 5.0), 1.0)
func test_raycast_against_a_box() -> void:
var ground: SimGround = SimGround.flat(-100.0)
ground.add_solid(AABB(Vector3(4.0, -1.0, -1.0), Vector3(2.0, 2.0, 2.0)))
assert_near(ground.raycast(Vector3.ZERO, Vector3(10.0, 0.0, 0.0)), 0.4, 0.0001)
assert_eq(ground.raycast(Vector3.ZERO, Vector3(3.0, 0.0, 0.0)), 1.0)
assert_eq(ground.raycast(Vector3(0.0, 5.0, 0.0), Vector3(10.0, 5.0, 0.0)), 1.0)
assert_eq(ground.raycast(Vector3(5.0, 0.0, 0.0), Vector3(10.0, 0.0, 0.0)), 0.0, "starting inside")
func test_raycast_against_terrain() -> void:
var ground: SimGround = SimGround.flat(0.0)
var hit: float = ground.raycast(Vector3(0.0, 2.0, 0.0), Vector3(0.0, -2.0, 0.0))
assert_near(hit, 0.5, 0.001)
assert_eq(ground.raycast(Vector3(0.0, 2.0, 0.0), Vector3(5.0, 1.0, 0.0)), 1.0)
assert_eq(ground.raycast(Vector3(0.0, -1.0, 0.0), Vector3(0.0, 3.0, 0.0)), 0.0, "starting below")
# A ray grazing up a slope finds where it enters.
var tilted: SimGround = _tilted()
var slope_hit: float = tilted.raycast(Vector3(0.0, 2.0, 2.0), Vector3(6.0, 2.0, 2.0))
assert_near(slope_hit * 6.0, 4.0, 0.01)
func test_body_blocked_respects_step_and_height() -> void:
var ground: SimGround = SimGround.flat()
ground.add_solid(AABB(Vector3(0.0, 0.0, 0.0), Vector3(2.0, 0.4, 2.0)))
ground.add_solid(AABB(Vector3(10.0, 2.0, 0.0), Vector3(2.0, 1.0, 2.0)))
assert_false(ground.body_blocked(Vector3(1.0, 0.0, 1.0), 0.4, 1.8, 0.45), "low step")
assert_true(ground.body_blocked(Vector3(1.0, 0.0, 1.0), 0.4, 1.8, 0.0))
assert_true(ground.body_blocked(Vector3(2.3, 0.0, 1.0), 0.4, 1.8, 0.0), "radius overlaps")
assert_false(ground.body_blocked(Vector3(2.5, 0.0, 1.0), 0.4, 1.8, 0.0))
assert_false(ground.body_blocked(Vector3(11.0, 0.0, 1.0), 0.4, 1.8, 0.0), "fits under")
assert_true(ground.body_blocked(Vector3(11.0, 0.0, 1.0), 0.4, 2.5, 0.0))