Spielerando

Push a hit enemy back exactly 100 pixels on any frame rate

Knockback made with a speed that shrinks each frame throws enemies a different distance on every computer, and a second hit during the push can launch them across the level. Here is a push whose length you choose and that stays the same everywhere.

Why this works

If you describe where the thing should be at each moment, the distance is built in. Each frame then only moves it by the change in that picture, and since the changes add up to the whole, the total is right whether you had many frames or few.

When not to use it

Don't use it when the push should depend on what is around, such as a heavy creature that a hit barely shifts, a slope that carries the body further, or a crowd that pushes back. Use real physics with weight and friction there.

In the full entry

  • What to build, step by step
  • Starting values and the reason for each
  • 3 common mistakes and the fix
  • 23 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 "Push a hit enemy back exactly 100 pixels on any frame rate" (read_entry knockback-that-travels-an-exact-distance) 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