body_exited fires for each body that leaves, even when something else is still on the plate. If body_exited sets your plate to up, the door closes the moment the player steps off, with a crate still sitting on it. Keep track of every body on the plate and release it only when none are left.
The code
Use this script as the plate itself: an Area3D with a CollisionShape3D child. Connect pressed and released to whatever it opens. Set bodies_needed to 2 for a plate that needs two things on it at once. To stop things like arrows or pickups from pressing it, put them on a collision layer the plate's mask does not include.
extends Area3D
## Pressure plate that stays down while anything is still standing on it.
## Give it a CollisionShape3D child. Connect pressed and released to your door, trap or light.
signal pressed
signal released
@export var bodies_needed := 1 # 2 = needs two things on it at once
var is_down := false
var _on := {} # what is standing on the plate right now
func _ready() -> void:
body_entered.connect(_on_enter)
body_exited.connect(_on_exit)
func _on_enter(body: Node3D) -> void:
_on[body.get_instance_id()] = true
_update()
func _on_exit(body: Node3D) -> void:
_on.erase(body.get_instance_id())
_update()
func _update() -> void:
var down := _on.size() >= bodies_needed
if down == is_down:
return
is_down = down
if down:
pressed.emit()
else:
released.emit()
What we measured
Two plates, each a real Area3D with a 2 × 0.5 × 2 m box shape. A player capsule and a crate capsule moved on and off both plates in the same order, 0.2 seconds per step. Two runs with the same results.
- Player steps on, then the crate is pushed on too: both plates down.
- Player steps off, crate still on: the true/false plate went up. The script stayed down.
- Player steps back on, then off again: the true/false plate went down and up again. That is 4 changes, for a plate that should have stayed down the whole time.
- Crate removed with
queue_free()while on the plate:body_exitedfired for it, and the script sentreleased. Its signals over the whole run:pressedonce,releasedonce.
Why it happens
Area3D sends one body_entered and one body_exited per body. A single true/false only remembers the last thing that happened, so any body leaving clears it, whoever else is still standing there. A list of bodies, or a counter, remembers all of them. Bodies that are freed while on the plate also send body_exited, so a destroyed crate releases it too.
What to change
bodies_needed: how many things must be on the plate at once.- Use
is_downif you need to check the plate without waiting for a signal.
A trap that should also hit someone already standing on it: spike trap and a player already on it.
Ready-made trap effects: Dungeon Trap VFX for Godot 4 has 27 presets in Stylized and Retro PSX looks, including Floor Spikes, Flame Jets, a Poison Gas Vent, a Laser Grid and Pressure Plates.
Tested in Godot 4.7 with the Compatibility renderer.
Ready-made: Dungeon Trap VFX for Godot 4 has 27 ready-made dungeon trap effects in Stylized and Retro PSX looks, including Pressure Plates, Floor Spikes, Flame Jets, a Poison Gas Vent and a Laser Grid.
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
- Refill the guard meter only after the hits stop
- Heal from the damage that actually landed
- 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