Zoom the map toward the mouse pointer instead of jumping to the middle
Zooming a big map should keep the thing you are pointing at under your finger. Many versions slide it away, or show empty space once the map gets smaller than the window. Here is the maths for a camera that zooms at the pointer and stays inside the map.
Why this works
Zooming should leave the thing you point at where it is. So note the spot under the pointer, change the zoom, then move the camera until that spot is under the pointer again. Fitting the camera to the map comes last, using the new zoom, so no empty edge appears.
When not to use it
Wrong where the camera follows a character or a fixed centre, such as a platformer or a game viewed from a single spot; zooming there should stay on the hero. On a phone, pinch zoom needs the middle of the two fingers instead of one pointer.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- 21 lines of example code with 4 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "Zoom the map toward the mouse pointer instead of jumping to the middle" (read_entry zoom-to-cursor-camera) 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