Spielerando

Soldiers that keep changing targets every time someone steps closer

If a unit always shoots the nearest enemy, a nimble enemy can run in circles and take no damage while the whole squad turns and turns. This entry shows how to make units stick to a choice, and when they must finally give it up.

Why this works

People and creatures commit to a choice and switch only when the gain is clearly worth the cost of turning. Judging every new candidate against the current one, not against nothing, copies that habit and stops endless twitching.

When not to use it

Do not use it for fast, twitchy games where reacting to the nearest threat is the skill, or for units that must always hit the weakest target. A sticky unit can keep shooting a harmless enemy while a dangerous one walks past. Choose by threat then.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • 26 lines of example code with 3 checks that pass
  • How your AI shows you that it works

Say this to your AI

Use the Spielerando entry "Soldiers that keep changing targets every time someone steps closer" (read_entry unit-target-stickiness-and-leash) 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