Tell a click from a drag so selecting units feels right at any zoom level
Selecting units with a box sounds simple, until a shaky click starts a tiny box that selects nothing, a box drawn backwards selects nothing at all, or a zoomed-in map selects the wrong units. Here is the logic that behaves the same for every hand and every zoom.
Why this works
A hand and a screen speak in pixels, but units live in the world. Deciding click or drag in pixels keeps the feel the same at any zoom, and converting the box into world positions before testing keeps the selection on the units the player actually sees.
When not to use it
Not the right tool on a touch screen, where a finger drag usually scrolls the map and a box needs a separate mode or button. It is also overkill for games where the player only ever picks one unit at a time.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- 33 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 "Tell a click from a drag so selecting units feels right at any zoom level" (read_entry drag-select-versus-click) 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