Skip to content

Camera fixes: clamp scrolling by view target, ignore minimap clicks outside the map - #18

Merged
tomluchowski merged 2 commits into
tomluchowski:shaders-improvementfrom
Upabjojr:split/camera-fixes
Aug 1, 2026
Merged

Camera fixes: clamp scrolling by view target, ignore minimap clicks outside the map#18
tomluchowski merged 2 commits into
tomluchowski:shaders-improvementfrom
Upabjojr:split/camera-fixes

Conversation

@Upabjojr

@Upabjojr Upabjojr commented Aug 1, 2026

Copy link
Copy Markdown

Two camera defects, one commit each:

  • Scrolling clamped by view target, not camera position. The camera is pitched 25° off vertical, so clamping its own position shifted the reachable view window: it overshot the map edge it faces and stopped short of the one behind it.
  • Minimap clicks outside the map. The minimap shows ground past the edge when the camera is near it; clicking there sent the camera flying at a destination it can never reach, leaving it shuddering against the edge for the rest of the game.

Split out of #16 so each topic can be reviewed on its own. Merging all of the split PRs reproduces the tree of #16 exactly.

🤖 Generated with Claude Code

Upabjojr and others added 2 commits August 1, 2026 10:22
Scrolling ran past the map edge on one side while stopping short of it
on the opposite side, in gameplay and in the map editor alike.

updateCameraFrameTime() clamped the camera node's own position to
[0, mapSize], but the camera is pitched DEFAULT_X_AXIS_VIEW (25 degrees)
off vertical, so the ground point it looks at lies z * tan(pitch) ahead
of it: between 1.4 and 7.5 tiles for z within [MIN_CAMERA_Z, MAX_CAMERA_Z].
Clamping the position therefore shifted the whole reachable view window
by that offset, overshooting the edge the camera faces and falling short
of the one behind it, for a total asymmetry of twice the offset.

Clamp so the view target stays inside the map instead, deriving the
offset from the camera's derived direction and the height it is about to
end up at, the same way getCameraViewTarget() does. Keeping the offset
signed leaves the limits correct under camera yaw, not just at the
default orientation.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
(cherry picked from commit 4d81fe4)
Clicking near the border of the minimap moves the camera there and leaves it
shuddering against the map edge for the rest of the game.

The minimap is a view of the ground around the camera, not of the map, so when
the camera is near an edge the minimap shows ground past it, and a click there
asks the camera to fly somewhere it cannot go: updateCameraFrameTime() keeps
the point the camera looks at inside the map. The flight is never within the
0.25 stopping distance of its destination, so it never ends, and every frame it
pushes the camera past the edge for the clamp to pull it back on the next one.
Hence the bouncing, and hence it outlasting the click.

flyTo() now aims at the nearest point on the map, which is where the camera was
going to stop anyway. Two things back that up. The clamp moved into
clampToMap() and is applied a second time just before the camera is placed, so
the flight, the circle and the spline modes, which all add to the position
after the first clamp, can no longer put the camera off the map even for the
single frame it took to be pulled back. And a flight that brings the view
target no closer than the frame before now gives up rather than press on, so no
destination the clamp does not predict can hang the camera again.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
(cherry picked from commit 0474176)
@tomluchowski
tomluchowski merged commit b64328c into tomluchowski:shaders-improvement Aug 1, 2026
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