A checkpoint for the player
Updated
Two gates are sensor colliders on the signal checkpoint: walking through one makes it the respawn point, and Respawn teleports the player’s Character Controller back to the last one reached.
Click the scene, walk through a green gate with WASD, wander off, then press Respawn to return to the gate. Drag to look around.
A checkpoint for the player
#pragma lifecycle(startup)
let player;let respawn = null;
// Each checkpoint is a group with a sensor Box Collider and a Signal Emitter with the signal 'checkpoint'.// The Player entity has a Character Controller.function startup() { player = findEntity('Player');
on('checkpoint', (event) => { if (event.eventType !== EventType.PhysicsCollider.IntersectionEnter) return; if (event.data.otherEntityId !== player.entityId) return;
const checkpoint = findEntity(event.entityId); respawn = checkpoint.position.clone(); log('Checkpoint reached:', checkpoint.name); });
on('player/died', () => { if (respawn) player.getComponent(CharacterControllerComponent).teleport(respawn); });}How it works
Section titled “How it works”The script is explained step by step in A checkpoint for the player.
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.
CheckpointRespawn.xrproj