Knockback and Invincibility Frames
Getting hit should push you back, take control for a blink, then protect you long enough to recover. Here are the numbers and the traps.

Key takeaways
- Knockback is an impulse away from the attacker (around 250 to 400 px/s at 720p) that decays over 0.15 to 0.25 seconds, plus a small upward hop in side-view games.
- Player i-frames last 0.6 to 1.5 seconds and blink at about 10 times per second. Enemies use per-attack hit lists instead of global invincibility.
- The classic bugs: knockback into pits, contact damage every frame, stunlock between two enemies, and i-frames that also ignore instant-death hazards.
Knockback pushes a character away from whatever hit it; invincibility frames (i-frames) make it immune to damage for a short time afterward. Together they turn a hit into a readable event: the player sees which way the force went, loses control for a fraction of a second, and then has a window to escape before the next hit can land. Without them, touching an enemy drains a health bar in a single frame. With badly tuned ones, players get juggled into pits.
Our game feel guide covers the visual side of a hit (flashes, shake, hit stop). This article is about the mechanical side: the movement, the timing and the rules for who can hit whom.
Knockback: impulse, decay and hitstun
There are two ways to implement knockback. Velocity impulse: set the character's velocity to a direction times a strength, then let friction or a decay bring it back to zero. Scripted displacement: move the character a fixed distance over a fixed time, ignoring physics. Impulse feels physical and interacts with slopes and walls; scripted displacement is predictable and easier to design levels around. Most 2D action games use impulse with strong decay.
- Direction: from the attacker's center (or the hitbox's center) to the target's center. For a sword swing, use the attacker's facing direction instead, so enemies always fly away from the swing even if overlapping.
- Strength: around 250 to 400 px/s at 720p for the player getting hit, scaled by the attack. Heavy attacks double it; light jabs might skip it.
- Decay: back to zero over 0.15 to 0.25 seconds. A short, sharp shove reads better than a long slide.
- Upward hop in side-view games: add an upward component of about a third to half of the horizontal strength. It lifts the character off the ground so ground friction does not eat the knockback, and it looks like a reaction.
- Hitstun (loss of control): 0.15 to 0.4 seconds for the player. Shorter than the knockback decay, so control returns while the character is still sliding, which feels responsive.
- Weight: a `knockbackResistance` per enemy (0 for small enemies, 0.8 for heavies, 1 for bosses) lets the same attack send a bat flying and barely move a golem.
Invincibility frames for the player
- Duration: 0.6 to 1.5 seconds. Platformers and bullet-heavy games sit toward the long end; methodical melee games toward the short end, or use none and rely on the enemy's attack rhythm instead.
- Blink at about 10 times per second (toggle visibility every 0.05 seconds, or fade alpha between 30 and 100 percent). Blinking is the universal signal that the character cannot be hurt right now.
- Keep the player solid. During i-frames, the player still collides with walls and floors; only damage is ignored. Some games also let the player pass through enemies during i-frames to escape crowds.
- Hazards versus enemies. Decide whether i-frames protect from spikes and lava. Most games say yes for damage, no for instant death like bottomless pits.
- Communicate the end. Speed up the blink in the last 0.2 seconds, or simply stop blinking cleanly. The player must know when they are vulnerable again.
Enemies need hit lists, not i-frames
If enemies get a second of invincibility after each hit, fast attacks and multiple players feel broken: your second sword swing does nothing. The usual fix is a hit list per attack. Each attack instance (one sword swing, one projectile) records which targets it has already hit and ignores them for the rest of its life. A swing that overlaps an enemy for six frames deals damage once; the next swing is a new attack with an empty list.
Add a very short global i-frame on enemies (0.05 to 0.1 seconds) only if you see several different attacks landing on the same frame and stacking unfairly. Piercing projectiles use the same hit list to hit each enemy once.
Dodge rolls and i-frames as a skill
Many action games give i-frames as part of a dodge, not only after damage. A roll of about 0.4 to 0.6 seconds with i-frames for roughly 0.2 to 0.35 of it, starting a few frames in, rewards timing rather than mashing. Values to start with: 0.05 seconds of startup with no i-frames, 0.25 seconds invincible, then 0.15 to 0.2 seconds of recovery when the character is vulnerable and cannot act. If you add a stamina cost, the roll becomes a resource decision too. Generous dodge i-frames make a game easier; they are one of the most effective difficulty settings to expose, and our difficulty curve guide covers framing options like that.
Bugs this pair usually causes
- Knockback into pits. The single most hated platformer death. Options: reduce knockback near ledges, remove the upward hop when a pit is behind the player, or design enemy placement so hits never push toward gaps. In a platformer, the safest default is modest knockback.
- Contact damage every frame. Overlap checks run every frame; without i-frames, standing in an enemy deals 60 hits per second. Always gate damage behind i-frames or a hit list.
- Stunlock between two enemies. Knocked from one into the other and back. I-frames that are longer than the hitstun fix it: the player regains control while still protected.
- Knockback through walls. A large impulse in one frame can tunnel through thin walls. Clamp the per-frame movement or move in steps against collision.
- Velocity stacking. Adding knockback to the current velocity can launch a running player across the screen. Replace velocity with the knockback impulse, do not add.
- I-frames saved forever. A timer that only counts down while the character is on screen, or during a certain state, can leave the player invincible after a cutscene. Run it on the game clock and clear it on respawn.
- Attacker inside the target. When the centers overlap, the direction vector is zero or random. Fall back to the attacker's facing direction.
How it combines with other mechanics
Health bars should blink with the character during i-frames, so the HUD agrees with the body. Checkpoints grant a second of i-frames on respawn. Power-ups like a star mode are long i-frames with a different look, and should end with a normal i-frame window. Bosses often get knockback resistance of 1 and use stagger instead: a separate meter that, when filled, gives the player a short opening. Bullet-heavy games usually clear nearby bullets when the player is hit, because i-frames alone do not stop a wall of bullets from killing again the moment they end. And in a metroidvania, contact damage, knockback and i-frames on spikes are part of how dangerous rooms feel.
A brief to paste
Rework getting hit in my 2D side-view action game. When the player is hit: replace their velocity with an impulse of 320 px/s away from the attacker plus 120 px/s upward, decaying to zero over 0.2 s; no input for 0.25 s; 1.0 s of invincibility with the sprite blinking 10 times a second and faster for the last 0.2 s. During i-frames the player passes through enemies but not walls, and still dies in pits. Remove the upward hop when a pit is within 2 tiles behind the player. Enemies use a hit list per attack so each sword swing damages each enemy once, and have a knockback resistance from 0 (bats) to 0.8 (knights). If attacker and target overlap, use the attacker's facing for direction. Add a dodge roll: 0.5 s total, invincible from 0.05 to 0.3 s. Expose every value as a dial.
On Startbase, dials show up in the game's engine panel (games template docs). Tune the i-frame length by standing between two enemies on purpose: if you can still get juggled, the i-frames are shorter than the time it takes to walk out.
Frequently asked questions
What are i-frames in games?
Invincibility frames are a short window, usually measured in frames or fractions of a second, during which a character cannot take damage. They appear after getting hit, during dodge rolls and on respawn.
How long should invincibility last after getting hit?
Commonly between 0.6 and 1.5 seconds for the player, with the character blinking the whole time. It should be longer than the hitstun so the player can escape before it ends.
Should enemies have invincibility frames?
Usually not long ones. Track which targets each attack has already hit instead, so one swing damages each enemy once while the next swing can hit again immediately.

