A sweeping searchlight
Updated
A searchlight sweeps left and right with a visible beam, which flares when you press F: a Spot Light with a Spot Light Beam, turned by a Behavior script under it.
Watch the beam sweep, and press F to flare it (click the scene first so it has the keyboard). Drag to orbit the camera, scroll to zoom.
A sweeping searchlight
#pragma lifecycle(startup, update)
const SWEEP = DEG_TO_RAD(40); // how far it turns each wayconst SPEED = 0.6; // radians of phase a second
let light;let beam;let baseYaw = 0;let phase = 0;
function startup() { light = self.parent; beam = light.getComponent(SpotLightBeamComponent); baseYaw = light.rotation.y; beam.setProps({ opacity: 0.2, length: 8.5 }); // ends where the beam meets the floor}
function update(dt) { phase += dt * SPEED; light.rotation.y = baseYaw + Math.sin(phase) * SWEEP;
if (Input.keyboard.isKeyReleased(Key.F)) { Tween.value(0.6, 0.2, (value) => beam.setProps({ opacity: value }), { duration: 1.5, ease: Ease.OutCubic }); }}How it works
Section titled “How it works”The script is explained step by step in A sweeping searchlight.
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.
SweepingSearchlight.xrproj