Line of sight through glass
Updated
A guard’s sight ray tests only the Default and Walls layers, so it is blocked by the wall but sees through the window on the Glass layer; an Enable On Signal shows when it spots the player.
Drag the blue player behind the grey wall to hide it, or behind the glass, where the guard still sees it and the pink alarm lights. Drag elsewhere to orbit the camera.
Line of sight through glass
#pragma lifecycle(startup, update)
const BLOCKS_SIGHT = [0, 3]; // Default and Walls; Glass (4) is left outconst eye = new THREE.Vector3();const target = new THREE.Vector3();
let guard;let player;let seen = false;
function startup() { guard = findEntity('Guard'); player = findEntity('Player');}
function update() { guard.getWorldPosition(eye); eye.y += 1.6; player.getWorldPosition(target); target.y += 1.6;
const blocked = PhysicsRaycaster.between(eye, target) .hit(null, { collisionLayers: BLOCKS_SIGHT, ignore: [guard, player] }); const nowSeen = !blocked; if (nowSeen !== seen) { seen = nowSeen; emit(seen ? 'guard/alert' : 'guard/lost'); }}How it works
Section titled “How it works”The script is explained step by step in Line of sight through glass.
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.
GlassSight.xrproj