← Pixel Dreamer Studio

Keep a pressure plate down while anything is still on it

Keep a list of the bodies on the plate and release it only when the list is empty.

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.

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

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