← Pixel Dreamer Studio

A fire or poison zone that keeps hurting while you stand in it

body_entered fires once per entry. Check who is inside on a timer.

Do the damage from a per-body timer that reads get_overlapping_bodies(), not from body_entered. body_entered fires once each time a body comes in: in our Godot 4.7 test a character that walked into a fire zone and stood there for 3 seconds took one hit, 5 HP. With the script below it took a hit as it walked in and one every 0.5 seconds after that: 7 hits in 3.25 seconds.

The code

Put this script on an Area3D with a CollisionShape3D child the size of your fire or gas cloud. Anything that should get hurt needs a take_damage(amount) method. For a molotov, add the zone where the bottle breaks: lifetime removes it when the fire goes out.

extends Area3D
## A fire, poison or gas zone that hurts every body standing in it, once every tick_time seconds.
## body_entered fires only once per entry, so this checks who is inside each physics frame instead.
## Give it a CollisionShape3D child. Bodies that should get hurt need a take_damage(amount) method.

@export var damage := 5.0
@export var tick_time := 0.5  ## seconds between hits on the same body
@export var lifetime := 5.0  ## seconds before the zone removes itself, 0 = stays

var _next := {}  # body -> seconds until its next hit


func _ready() -> void:
	if lifetime > 0.0:
		get_tree().create_timer(lifetime, false).timeout.connect(queue_free)


func _physics_process(delta: float) -> void:
	var inside := get_overlapping_bodies()
	for b in _next.keys():
		if not is_instance_valid(b) or b not in inside:
			_next.erase(b)  # it left: the next time it walks in, it is hit right away
	for b in inside:
		if not b.has_method("take_damage"):
			continue
		var left: float = _next.get(b, 0.0) - delta
		if left <= 0.0:
			b.take_damage(damage)
			left += tick_time
		_next[b] = left

What we measured

A CharacterBody3D with a capsule and 100 HP, and a zone with a cylinder shape of 1.5 m radius, 5 damage a hit.

Two runs gave the same numbers.

Why body_entered is not enough

body_entered and body_exited report changes. A body that stays inside makes no more signals, so damage done there happens once per entry, however long the body stands in the fire. get_overlapping_bodies() returns who is inside right now, kept up to date by the physics step, so it can be asked every frame. Each body gets its own countdown, so one that steps in late is not hit early or late because of another.

What to change

Ready-made survival effects: Zombie Outbreak & Survival VFX for Godot 4 has 25 presets in Stylized and Retro PSX looks, including a Molotov that burns for 5 seconds, Infection Fog, Spore Cloud, a Road Flare and Signal Smoke.

Tested in Godot 4.7 with the Compatibility renderer.

Ready-made: Zombie Outbreak & Survival VFX for Godot 4 has 25 ready-made zombie survival effects in Stylized and Retro PSX looks, including a Molotov that burns for 5 seconds, Infection Fog, Spore Cloud, Road Flare and Signal Smoke.

More how-tos for Zombie Outbreak & Survival VFX for Godot 4: Keep a chasing horde from stacking into one enemy · An enemy that dies once, however many hits land

More how-tos: Hazards, traps and attacks