A pressure plate that counts what stands on it
Updated
A sensor plate counts the bodies on it: the first one in opens the door, the last one out closes it again, each through an Enable On Signal on the door.
Drag a crate onto the green plate to open the door; add the other one, then take both off to close it. Drag elsewhere to orbit the camera.
A pressure plate that counts what stands on it
#pragma lifecycle(startup)
const onPlate = new Set();
// The Plate is a group with a thin sensor Box Collider and a Signal Emitter with the signal 'plate'.function startup() { on('plate', (event) => { const id = event.data.otherEntityId; if (!id) return;
const before = onPlate.size; if (event.eventType === EventType.PhysicsCollider.IntersectionEnter) onPlate.add(id); if (event.eventType === EventType.PhysicsCollider.IntersectionExit) onPlate.delete(id);
if (before === 0 && onPlate.size > 0) emit('door/open'); if (before > 0 && onPlate.size === 0) emit('door/close'); });}How it works
Section titled “How it works”The script is explained step by step in A pressure plate that counts what stands on it.
Open it in XR Creator
Section titled “Open it in XR Creator”Download the project file below, then import it in XR Hub with Projects › New › Import, as described in Projects and templates. It opens in XR Creator with the same scene you see running above, each script already attached to its Behavior entity. From there you can edit the scripts, adjust components and their props, preview your changes, and deploy the result as a world of your own.
PressurePlate.xrproj