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.
- An enemy with 500 health: 100 removed, and both ways heal 20.
- An enemy with 10 health left: 10 removed. Healing from the damage rolled gave 20, the script 2.
- An enemy already at 0, still on screen: 0 removed. Damage rolled gave 20, the script 0.
- 20 slimes with 15 health each: 300 removed. Damage rolled gave 400, more than all the damage dealt, the script 60.
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
steal: the share of damage that comes back, 0.2 for 20%.- For damage over time, call it on every tick with that tick's damage.
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
- Turn a 2D character left without the flicker
- A line or rectangle attack that hits what the player sees
- A scare that plays once, and only for the player
- An attack that hits even when a frame is slow
- Growing one cloud or aura zone grows all of them
- A parry window that is the same length on every screen
- A pair of portals that sends you through once
- An expanding shockwave that hits each enemy once
- Explosion damage that walls block, on the frame it goes off
- A fire or poison zone that keeps hurting while you stand in it
- A spike trap that hits whoever is already standing on it
- Who is inside an AoE attack circle
- Block only attacks from the front
- A sword hitbox that hits each enemy once per swing
- Slows and roots that overlap
- Blink forward without going into or through walls
- Knockback that the walk code does not cancel
- Random spots spread evenly inside a circle
- Keep a pressure plate down while anything is still on it
- Refill the guard meter only after the hits stop
- Let the shield take what it can and pass the rest of the hit to health
- A saw blade that slides along its path at a steady speed
- Explosion damage that reaches big enemies
- A spinning laser that hits everything it sweeps over