Camera
Learning paths through this topic
Turning the slanted map view by a quarter makes everything jump to another place
To let players look behind a tall building you turn the whole map view, but the spot they were looking at flies off the screen and clicks land on the wrong tile. Here is how to turn the map itself around its middle, keep the view where it was, and turn clicks back.
Drawing a selection box near the edge scrolls the map but the box goes wrong
When you drag a box over many units and the map scrolls along, the box often selects the wrong area, because it was remembered in the wrong kind of position. Here is what to store at the start of the drag, how the box is rebuilt on every frame, and how to tell a click from a drag.
The camera sticks at the map edge, or keeps pushing when I turn away
When the camera runs into the edge of the map and you keep holding a diagonal key, one direction should stop and the other should carry on along the edge. Often the camera stops dead, or hidden speed makes it linger before it reacts. Here is how to stop one direction at a time and how to slow down before the edge.
Zooming out of a 3D map should lift the view toward looking straight down
Close to the ground a low, tilted view feels like standing among the buildings, but zoomed out the same tilt hides the map behind hills and wastes the screen on the sky. Here is how one zoom value can set height, distance and tilt together, so the spot in the middle never slides.
Two fingers zoom the map but the spot between them slides away
On a touch screen the person pinches to zoom and drags with the same two fingers, and the map should follow both like paper under the fingers. Zooming around the screen center feels wrong, and lifting one finger makes the view jump. Here is the calculation from the start of the gesture and the traps at its ends.
Tall buildings pop in at the bottom of the screen, because the tile range is cut too tight
In a slanted tile view, drawing only the tiles that touch the screen is a big saving, but a tall tower whose foot is below the edge should still show its top. Here is how to turn the screen corners into the range of tiles to draw, and how much room to add.
One wheel notch zooms a lot on one computer and a touchpad swipe barely moves
Mouse wheels, touchpads and pinch gestures report their movement in very different units, so the same zoom code feels jumpy on one device and dead on another. Here is how to bring them to one scale, why zooming has to multiply instead of add, and where the limits go.
I can zoom out until the map is a speck, or not far enough to see all of it
The lowest zoom has to depend on the map and the window, not a number picked once. Otherwise small maps float in empty space and big ones never fit, and after resizing the window the view is suddenly too far out. Here is how to work out the limit and what to do when it clashes with the highest zoom.
Show the whole selected army, not hidden behind the menu or zoomed into one soldier
A key that frames the selected units sounds simple, yet it zooms absurdly close on a single unit, cuts off units at the edges, and hides them under the bottom panel. Here is how to size the view, with room around the group, and where the center must go when panels cover part of the screen.
The camera behind the character goes through walls or snaps back and forth
A camera that hangs behind the player ends up inside pillars and walls, hiding everything. Pushing it forward helps, but doing it in both directions at the same speed makes it flicker when walking past posts. Here is a fast pull-in and slow return, and what to do very close.
Zooming with the mouse wheel should zoom into the point you point at
A map or editor that zooms around its centre makes the thing you wanted to see slide away. Players expect the spot under the pointer to stay where it is. Getting this exact needs one small adjustment of the camera, and the steps of the wheel must multiply instead of add.