03 / Impact
Knockback
shove the target away from the blow
Knockback shoves the target away from whatever hit it, then lets friction stop the slide. The distance tells the player how strong the blow was and where it came from, and the gap it opens gives both sides room to reset. With it off, the target soaks the hit in place; with it on, it skids back and settles.
- Melee and projectile hits
- Explosions, which push everything outward from the blast
Prompts to paste
On hit, set the target's velocity along the line from attacker to target, scaled by the attack's knockback force over the target's weight, lock out its own movement input for about 0.2 s, and let friction slow it rather than moving it a fixed distance.
Implement knockback in the hit handler. Work out the direction from the attacker to the target (on the ground plane, plus a slight upward part in 3D), and set the target's velocity to that direction times attack.knockback / target.weight. Put the target into a 0.2 s hitstun state that ignores its movement input while physics and collisions keep running, and let ground friction bring it to rest. Make knockback, weight and hitstun tunable.
Examples
Direction comes from the hit
Push along the line from the attacker, not the way the target is facing, so the slide always points away from the blow.
Weight tells a story
Dividing by weight sends small enemies flying and barely moves big ones, which tells the player what they're up against.
A little lift in 3D
A small upward part of the push keeps targets from catching on bumps in the floor.
Pitfalls
Teleporting instead of pushing
Moving the position directly skips collision checks, so a target can end up inside a wall. Set the velocity and let physics move it.
Forgetting hitstun
If the target's own movement code keeps running, it overwrites the push on the next frame and nothing visibly happens.
Too much for the arena
If every hit sends enemies out of reach, combos fall apart. Match the force to the attack's range.
Starting values
| Setting | Value | Note |
|---|---|---|
| Push speed | 4–10 m/s in 3D, 150–400 px/s in 2D | |
| Friction | brings the slide to rest in 0.15–0.3 s | |
| Hitstun | 0.15–0.3 s |