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
+9 -21
View File
@@ -1,7 +1,7 @@
## The authoritative fixed-tick game state. It takes commands and a seed and nothing
## else: no scene tree, no wall clock, no unseeded randomness.
##
## Movement here is a flat placeholder until the character controller lands in v0.2.
## Movement rules live in Movement; the world's solid shape lives in `ground`.
class_name Simulation
extends RefCounted
@@ -10,6 +10,8 @@ const SECONDS_PER_TICK: float = 1.0 / Tuning.TICK_RATE_HZ
var tick: int = 0
var entities: EntityRegistry = EntityRegistry.new()
var rng: SimRng
## Terrain and solids. Flat until the island generator provides a heightfield.
var ground: SimGround = SimGround.flat(0.0)
## Player entity ID -> { command tick -> PlayerCommand }
var _pending: Dictionary = {}
@@ -26,7 +28,10 @@ func add_player() -> int:
var player: SimEntity = entities.create(SimEntity.ARCHETYPE_PLAYER)
var spawn: RandomNumberGenerator = rng.stream("spawn")
var size: float = Tuning.WORLD_SIZE_METRES
player.position = Vector3(spawn.randf() * size, 0.0, spawn.randf() * size)
var x: float = spawn.randf() * size
var z: float = spawn.randf() * size
player.position = Vector3(x, ground.terrain_height(x, z), z)
player.on_ground = true
player.health = Tuning.PLAYER_MAX_HEALTH
_players.append(player.id)
_pending[player.id] = {}
@@ -63,25 +68,7 @@ func step() -> void:
func _apply_command(player: SimEntity, command: PlayerCommand) -> void:
# With no command this tick, the player keeps looking the same way and stands still.
if command == null:
return
player.yaw = command.yaw
player.pitch = command.pitch
var move: Vector2 = command.move_vector()
if move.length() > 1.0:
move = move.normalized()
var angle: float = command.yaw_radians()
var forward: Vector3 = Vector3(sin(angle), 0.0, cos(angle))
var right: Vector3 = Vector3(cos(angle), 0.0, -sin(angle))
var speed: float = (
Tuning.SPRINT_SPEED if command.is_pressed(PlayerCommand.BUTTON_SPRINT)
else Tuning.WALK_SPEED
)
var delta: Vector3 = (right * move.x + forward * move.y) * speed * SECONDS_PER_TICK
var size: float = Tuning.WORLD_SIZE_METRES
player.position = (player.position + delta).clamp(Vector3.ZERO, Vector3(size, 0.0, size))
Movement.step(player, command, ground)
## SHA-256 hex digest of a canonical encoding of the whole state.
@@ -101,6 +88,7 @@ func state_hash() -> String:
buffer.put_32(entity.health)
buffer.put_32(entity.yaw)
buffer.put_32(entity.pitch)
buffer.put_u8((1 if entity.on_ground else 0) | (2 if entity.crouching else 0))
for value: float in [entity.position.x, entity.position.y, entity.position.z]:
buffer.put_64(roundi(value * 1000.0))
for value: float in [entity.velocity.x, entity.velocity.y, entity.velocity.z]: