Spielerando

Make the camera follow the hero without showing empty space past the level

A camera that sticks to the hero shows the grey void at the level's edges, and a camera that is clamped carelessly shakes when the level is smaller than the screen. This entry gives a follow that eases, stops at the edges and centres a small level.

Why this works

The view is a window onto a fixed world, so it can only be valid where the window stays inside the world. Aiming at the hero first and correcting afterward keeps the hero's wish and the world's limit apart, and a world smaller than the window has one honest answer, the middle.

When not to use it

Skip it in a game that should show the hero dead centre at all times, or in one where the empty space is part of the look, such as a drifting space scene. There a plain lock on the hero is the better choice.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • 12 lines of example code with 5 checks that pass
  • How your AI shows you that it works

Say this to your AI

Use the Spielerando entry "Make the camera follow the hero without showing empty space past the level" (read_entry action-camera-follow-level-edges) in my game. Build it step by step, and show me how you checked that it works.

Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP