Files
claudeandClaude Opus 5.5 53e3d92496
Ashlar checks / tooling (push) Successful in 5s
Modern third-person camera defaults, collision ease-out and aim mode
- Shoulder view, auto shoulder switch, standing preview, deferred preview
  rotation, move 360, smooth view change and [Game] smooth movement are
  on by default.
- Collision ease-out: the camera still snaps in on collision but eases
  back out (0.15 s half-life, 60 u/s minimum speed).
- Aim mode: with a ranged weapon or a spell readied in third person the
  view stays over the shoulder, moves closer and narrows the FOV. Camera
  interface v2 adds getAimWeight and enable/disable functions.
- Pure math in camera/ease.lua with unit tests; SCENARIO=camera with
  PASS/FAIL checks; docs in docs/ashlar/CAMERA.md.
- ashlar-run.sh deletes stored Lua settings before each run so changed
  defaults are tested.

Closes #29

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

61 lines
2.2 KiB
Lua

-- Ashlar: pure math for the third person camera (no engine calls), so it can be unit tested.
--
-- Collision recovery: when an obstacle pulls the camera in, the engine clamps the distance at once (it must, or the
-- camera would clip). When the obstacle is gone the camera should ease back out instead of snapping. recoverDistance
-- moves the preferred distance from the current (clamped) distance towards the target with an exponential ease-out,
-- with a minimum speed so it always arrives.
--
-- Aim mode: while a ranged weapon or a spell is readied, the camera blends towards a tighter framing. approach moves
-- the aim weight towards 0 or 1 with the same ease-out, and lerp applies the weight to distance and field of view.
local M = {}
-- Fraction of the remaining gap closed in dt seconds, for an ease-out whose half of the gap closes in halfLife seconds.
function M.easeFactor(dt, halfLife)
if dt <= 0 then
return 0
end
if not halfLife or halfLife <= 0 then
return 1
end
return 1 - 0.5 ^ (dt / halfLife)
end
-- New preferred distance for this frame. Moving in (target <= current) is immediate; moving out eases.
-- minSpeed (units per second) keeps the tail of the ease from crawling.
function M.recoverDistance(current, target, dt, halfLife, minSpeed)
if target <= current then
return target
end
if dt <= 0 then
return current
end
local gap = target - current
local step = math.max(gap * M.easeFactor(dt, halfLife), (minSpeed or 0) * dt)
return math.min(current + step, target)
end
-- Moves value towards target with the ease-out, snapping when within epsilon.
function M.approach(value, target, dt, halfLife, epsilon)
local next = value + (target - value) * M.easeFactor(dt, halfLife)
if math.abs(target - next) <= (epsilon or 1e-3) then
return target
end
return next
end
function M.lerp(a, b, t)
return a + (b - a) * t
end
-- Aim framing for weight w in [0, 1]: distance and field of view are scaled towards their aim multipliers.
function M.aimDistance(distance, aimScale, w)
return distance * M.lerp(1, aimScale, w)
end
function M.aimFieldOfView(baseFov, aimScale, w)
return baseFov * M.lerp(1, aimScale, w)
end
return M