# How to Add Knockback When Hit by an Enemy in Scratch > Compare x positions and push the player away from the enemy. Learn how to add knockback when hit by an enemy in Scratch with clean block recipes, testing tips, and related guides. ## Minimal Working Block Recipe Compare x positions and push the player away from the enemy. Test this minimal version first, then tune numbers like speed, gravity, or timing to match your game feel. **Add Knockback When Hit by an Enemy script** - if then if <(x position) < ([x position] of [Enemy])> then change x by (-30) else change x by (30) Try it: Clear physical feedback when taking damage. ## Debugging Checklist & Next Steps If it behaves unexpectedly, verify initial variable resets on the green flag and check that continuous checks sit inside a forever loop. - [Related Deep-Dive Guide](/en/techniques/hit-detection/): Explore full mechanics and variations. - [All 120 Scratch How-To Recipes](/en/howto/): Return to the reverse lookup index. Updated: 2026-11-23 Author: [Takamasa Suzuki](https://scratch.gmnavi.jp/about/author/) Japanese Edition: https://scratch.gmnavi.jp/howto/knockback/ [Scratch Daizen (English)](https://scratch.gmnavi.jp/en/)