Invincibility frames (i-frames) are the window after a hit where nothing can hit you again. Here it lasts 1.2 s, you blink the whole time, and a mistake costs one mask instead of one per tick.
- i-frames (1.2 s): with the technique, Ignored: n ms of i-frames left. without it, You lose another mask: contact damage tries again every tick.
I-frames after a hit: one mistake, one mask
Contact damage is why they exist. An enemy's body or a damage pad is a hitbox that's always on and tries to hit you on every physics tick, 120 times a second. Without the window, standing inside an enemy for an instant would cost a mask per tick. The hit also knocks you back and takes your control for 0.2 s; the rest of the 1.2 s is time to get clear. Health is five masks, the same as Hollow Knight starts you with.
Hazard respawn: spikes that cost a mask, not a life
Spikes, pits and the void don't kill. They cost a mask and put you back on the last safe ground you stood on; only the last mask sends you to the checkpoint. Health is the error budget for the area, and a spike shouldn't make you replay what you already knew how to do. I-frames never protect you from spikes, or an enemy hit would buy you 1.2 s to cross a spike pit.
1 · technique on 2 · T pressed: off Walks into the spikes on purpose. With hazard respawn it loses a mask and reappears on the last safe ground; after T the spikes kill and it starts over from the checkpoint.
You're in control from the first frame. The steps are below.
- Walk right with → into the first spikes. You lose one mask and reappear on the last safe ground, not at the checkpoint.
- Keep holding → when you reappear. It doesn't move you until you let go (half a second at most), so the same reflex doesn't put you back on the spikes.
- Jump the spikes with Space and drop into the pit at the end: the void works the same.
- Press T and touch the spikes again. Now they kill, and you start over from the checkpoint.
On a phone you get on-screen buttons: ← → to move, JUMP, and T for the technique.
The real game, running in your browser. The first load fetches the engine; after that it is cached.
How to implement i-frames and hazard respawn
- One invulnerability timer in the health component. A hit that lands sets it; while it runs, every hit is refused and contact hitboxes try again next tick.
- Knock the player away on a hit. If they're still inside the enemy when the timer runs out, the next hit lands on the very next tick.
- Let the movement code ask before it dies. For a hazard, charge a mask and send the player to the last safe ground instead. Only record ground that's really safe: static, with floor on both sides and no hazard nearby.
- Make hazard hits ignore invulnerability.
The code in Godot 4
## Aplica un golpe. Devuelve false si no hizo efecto (ya muerto o invulnerable).
func take(hit: Hit) -> bool:
if is_dead():
return false
if _invulnerable > 0.0 and not hit.ignores_invulnerability:
return false
current = maxi(current - hit.damage, 0)
_invulnerable = invulnerability_time
changed.emit(current, maximum)
damaged.emit(hit)
if current == 0:
died.emit(hit)
return true @export_group("Vida y daño")
@export_range(1, 12) var max_health := 5
## I-FRAMES: invulnerabilidad tras recibir daño. Tiempo para salir del peligro.
@export_range(0.0, 3.0, 0.05, "suffix:s") var invulnerability_time := 1.2
## Empujón al recibir daño: horizontal (alejándose del golpe) y vertical.
@export var hurt_knockback := Vector2(300.0, 330.0)
## Tiempo sin control tras el golpe: el empujón se nota, pero no desespera.
@export_range(0.0, 0.6, 0.01, "suffix:s") var hurt_lock_time := 0.2 The blink reads the same timer, so it stops exactly when you can be hit again.
Quick answers
How long should invincibility frames last?
Long enough to get out of danger: 1.2 s after a hit here, 0.2 s of it without control. A dodge is much shorter: 0.21 s.
Should spikes kill or take health?
If your game has health, take health. Here a spike costs one mask and returns you to the last safe ground. Only the last mask kills.
Discussion
Comments are hosted on GitHub Discussions — sign in with GitHub to reply.