← Pixel Dreamer Studio

Heal from the damage that actually landed

Cap the damage at the target's remaining health before working out the heal.

If life steal uses the damage number you rolled, a hit on a nearly dead enemy, or on one already dead and playing its death animation, heals as much as a hit on a full-health boss. In our Godot 4.7 test, 20% life steal and hits of 100 against 20 slimes with 15 health each healed 400, from 300 health actually removed. Use the smaller of the damage and the health the target had left: 60.

The code

Call heal_for(target_health_before_the_hit, damage) with the damage after armor and other reductions, and add the result to the attacker. A target at 0 health or below gives nothing, so a corpse still on screen cannot be farmed.

extends Node
## Life steal that heals from the damage that really landed, not from the number rolled.
## Pass the damage after armor and the target's health before the hit.

@export var steal := 0.2  # 0.2 = 20% of the damage dealt comes back as health


func heal_for(target_health: float, damage: float) -> float:
	var dealt := minf(damage, maxf(target_health, 0.0))  # overkill and dead targets give nothing
	return dealt * steal

What we measured

20% life steal and hits of 100. Two runs with the same numbers.

Why it happens

The number you roll is how hard the hit could be, not how much health it took. Against big enemies the two are the same, which is why this is easy to miss in testing. Against weak or dying enemies the gap is large, and area attacks over many small enemies multiply it.

What to change

Ticks that come out one short: damage over time timer. A shadow dash that does not end inside walls: blink teleport.

Ready-made dark magic: Dark & Shadow VFX for Godot 4 has 44 presets, including Soul Drain, Shadow Step, Void Portals, Binding Chains and Curse Marks.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Dark & Shadow VFX for Godot 4 has 44 ready-made dark magic effects, including Soul Drain, Shadow Step, Void Portals, Binding Chains and Curse Marks.

More how-tos: Hazards, traps and attacks