Spielerando

An enemy keeps switching between chasing and walking away at the edge of its range

When one single distance decides between chasing and patrolling, a player standing near that line makes the enemy twitch back and forth. This entry shows the small change that makes the enemy decide once and stick with it.

Why this works

One single line makes decisions flip whenever the player stands on it. Using a lower bar to start and a higher one to stop gives the enemy a margin of commitment, and a short search before giving up matches how a person would react.

When not to use it

Skip it for simple enemies that are meant to be dumb, such as ones that always run at the player or follow a fixed route, or when the arena is so small that the gap would cover the whole room. Use one plain rule there.

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
  • 28 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 "An enemy keeps switching between chasing and walking away at the edge of its range" (read_entry enemy-chase-hysteresis-no-flicker) 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