Creating a Trapdoor Platform
Build classic obby trapdoors: platforms that vanish on touch and return after a delay. Mark players and trapdoor props with traits, detect collisions to hide them, queue respawns with world time, and restore them in onGameTick.
Script
Hello hello and welcome back to Jamango Academy! In this episode, we’re building a classic obby obstacle: trapdoors — platforms that disappear when touched and respawn after a few seconds. Great for tension and variety! We’ll use traits, collision detection, a simple timer, and a few MangoLango functions to tie it all together.
Create traits#
We’ll identify players in code with a PlayerTrait (empty schema) and mark trapdoor props with TrapdoorPropTrait. Attach TrapdoorPropTrait to your platform prop with the wrench; PlayerTrait is attached via script on join.
tsimport * as J from "jamango"; const PlayerTrait = J.defineTrait("Player", J.schema.object({})); export const TrapdoorPropTrait = J.defineTrait( "TrapdoorProp", J.schema.object({}), { name: "Trapdoor", description: "Disappears when stepped on!",
Make the trapdoor disappear on touch#
When a player steps on the trapdoor, shrink it to 0 (invisible/non-solid) and queue a respawn time 3 seconds later using world time.
tsconst trapdoorsToRespawn: [propId: number, respawnTime: number][] = []; J.onEntityCollisionStart( { source: [PlayerTrait], target: [TrapdoorPropTrait], }, (playerId, trapdoorId) => { J.setEntityScale(trapdoorId, 0); trapdoorsToRespawn.push([trapdoorId, J.getWorldTime() + 3]);
Respawn after a delay#
Each frame, check if any queued trapdoors are ready. Loop backwards so removals don’t affect iteration.
tsJ.onGameTick((_, time) => { for (let i = trapdoorsToRespawn.length - 1; i >= 0; i--) { const [trapdoorId, respawnTime] = trapdoorsToRespawn[i]; if (time >= respawnTime) { J.setEntityScale(trapdoorId, 1); trapdoorsToRespawn.splice(i, 1); // remove from list } } });
Tip: Adjust the delay by changing + 3 to any number of seconds. Try chaining several trapdoors for chaotic races in multiplayer!