Skip to content

Add camera follow and shake, and gamepad input - #5

Merged
RohanFredriksson merged 1 commit into
claude/gameplay-api-batch3from
claude/gameplay-api-batch4
Oct 16, 2026
Merged

RohanFredriksson merged 1 commit into
claude/gameplay-api-batch3from
claude/gameplay-api-batch4

Conversation

@RohanFredriksson

Copy link
Copy Markdown
Owner

Batch 4 of ROADMAP.md. This is stacked on #4 (batch 3), so it targets that branch and the diff shows only batch 4. Merge #4 first, then change this PR's base to master.

Changes

  • CameraFollow component (components/camerafollow.hpp):
    • Follows its own entity by default, or another entity by id (setTarget).
    • Options: an offset, smoothing in seconds (exponential, so it behaves the same at any frame rate), a dead zone, and bounds that keep the view inside them, or centre it when the view is larger.
    • Snaps on start and when the target changes. Serialised and editable in the inspector.
    • The logic is in apply(camera, target, dt), so it is unit-tested without a window.
  • Camera shake: Camera::shake(intensity, duration), plus stopShake, isShaking and getShakeOffset.
    • A random offset that fades out quadratically. The stronger of two overlapping shakes is kept.
    • Only getView changes, so getPosition, CameraFollow and mouse world coordinates aren't disturbed. A paused scene holds the offset.
  • GamepadListener: polled each frame after glfwPollEvents.
    • Buttons have down, begin down and end down, compared with the previous poll. A disconnect releases every button.
    • Axes have a configurable dead zone, applied radially to sticks. Stick y points up, and triggers go from 0 to 1.
    • setState lets tests and tools fake a pad.
  • Console: shake <intensity> [duration] and gamepads.
  • Demo: hard impacts shake the camera, a gamepad's left stick pans, and A drops a box.
  • Docs: README gets a "Camera and Gamepads" section. CLAUDE.md and ROADMAP.md are updated.

Testing

  • New unit test tests/test_camera.cpp covers:
    • shake staying within its intensity, fading, pausing, stopping, and a weaker shake not cutting a stronger one short;
    • follow snapping, frame-rate-independent smoothing (60 and 30 fps land in the same place), dead zone, offset, and bounds (clamped, and centred when the view doesn't fit);
    • follow settings in JSON;
    • gamepad begin, end, disconnect, dead zone, stick direction and trigger range.
  • New engine test tests/test_camera_engine.cpp covers following through the scene, switching and losing the target, shake from the console, and that a faked pad is replaced by the next real poll.
  • Not covered: a real controller, since none can be connected in this environment. It is worth trying the demo with a gamepad.
  • All 12 tests pass locally in the ASan build and the Release build.

🤖 Generated with Claude Code

https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV


Generated by Claude Code

Batch 4 of ROADMAP.md.

- CameraFollow component: follows its own entity, or another by id, with
  an offset, exponential smoothing that doesn't depend on frame rate, a
  dead zone, and bounds that keep the view inside them (or centre it when
  it doesn't fit). It snaps on start and when the target changes, and is
  serialised. The logic is in apply(camera, target, dt), so it is tested
  without a window.
- Camera::shake(intensity, duration) moves the view by a random offset
  that fades out quadratically, keeping the stronger of overlapping
  shakes. Only getView changes, so the camera's position, following and
  mouse world coordinates are unaffected. A paused scene holds the offset.
- GamepadListener: polled each frame after glfwPollEvents. Buttons have
  down, begin down and end down (compared with the previous poll, and a
  disconnect releases everything). Axes have a configurable dead zone,
  applied radially to sticks. Stick y points up, and triggers go from 0
  to 1. setState lets tests and tools fake a pad.
- Console commands shake and gamepads.
- The demo shakes the camera on hard impacts, and a gamepad's left stick
  pans and A drops a box.

Tests: new unit test test_camera for shake, follow (snap, frame-rate
independent smoothing, dead zone, offset, bounds, json) and gamepad state,
and engine test test_camera_engine for following through the scene,
changing and losing the target, shake from the console, and per-frame
polling.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015cNAkNqoDWA5gFReD1AsqV
@RohanFredriksson
RohanFredriksson merged commit 73e950b into claude/gameplay-api-batch3 Oct 16, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants