Knockback that pushes the right way, a controlled distance, without errors
Getting hit should push the character away from the attacker. Unlucky overlaps produce a push in no direction, or one that flings a heavy enemy as far as a light one. Here is how to pick the direction safely and how to set the distance instead of a speed.
Why this works
Players judge a push by where the enemy ends up, so decide that distance first and work out the speed from it. Choosing the side from who stands where, not from the attack, means the push always sends the enemy away from the one who hit it.
When not to use it
Do not push when the fight is about holding a position, such as a guard that must stay put, or a boss that should not be moved. Use a short flinch in place, and give heavy enemies a high resistance rather than none.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- 31 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 "Knockback that pushes the right way, a controlled distance, without errors" (read_entry knockback-direction-and-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