An enemy keeps switching between two players at equal distance
With two possible targets about equally near, the enemy turns left, then right, then left again, and gets nowhere. Here is the small rule that makes it commit, when it is allowed to change its mind, and when it must drop a target for good.
Why this works
Two nearly equal distances keep swapping places, so a rule of always taking the nearest makes the unit face a new way every moment and go nowhere. A small bonus for the current choice means it only switches when the gain is real.
When not to use it
Skip it for units that should be easy to distract or pull away, like a decoy that is meant to steal attention, or a fast swarm where each member picks its own. A loyal enemy ignores a target that is suddenly the real danger.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 4 common mistakes and the fix
- A diagram of every state
- 17 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 "An enemy keeps switching between two players at equal distance" (read_entry keep-the-chosen-target-until-clearly-better) 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