Spielerando

Following a selected unit should end when I scroll away, but not on a twitch

A camera locked to a unit is useful until you want to look elsewhere, and then it fights you or lets go at the slightest touch of the mouse at the screen edge. Here is how the camera should decide that you really meant to look away, and when it must let go by itself.

Why this works

A hand makes small accidental movements all the time, but a deliberate scroll adds up. So the game counts the total distance moved and lets it drain away slowly: a twitch never reaches the limit, while a real push ends the following within a moment.

When not to use it

Do not let scrolling end the following when the player cannot afford to lose the unit, such as an escort mission or a duel, or when many players use shaky input like a trackpad on a lap. Make leaving a deliberate key instead.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • A diagram of every state
  • 24 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 "Following a selected unit should end when I scroll away, but not on a twitch" (read_entry strategy-follow-unit-until-manual-pan) 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