Build an interactive VR room
Goal
Start a life-size room with teleport locomotion, snap turning, physics props and signal-driven switches.
Files you will edit
src/game.tssrc/xr.ts
Steps
- Copy
templates/vrand keep the character'schar.visitasset id. The host accepts the same published character lookup as Visit. Press Play on desktop or Enter VR in a headset; a supported phone offers View in your room. - In
src/game.ts, change the button's effect and greeting. The button extends the engine's Lever with timed reset; the SlidingDoor reads the named lever signal. Keep those premade rules. - In
src/xr.ts, keep the walkable floor bounds and furniture clearance aligned with the room.createRoomControlssamples a ballistic arc, validates its landing, and teleports only on stick release. It tracks exclusive grips for both controllers and passes release velocity to physics. Use itscancel()method before restarting or moving the rig. - Keep the controls help visible: headset arc/snap/grip/trigger/menu, desktop movement/use/grab, gamepad sticks/buttons, and phone placement and touch controls.
Verify
Run npx vitest run templates/vr packages/xr. Press the button once, pull the lever to open the door, throw one prop from each hand, then restart. Invalid arc landings must remain pink and never move the rig. Check headset and phone behavior on real devices after the headless tests pass.
See also
- Start a game
packages/xr/README.md— XR API and integration.