Drag an object at arm's length
Updated
While the left button is held, CoordinateSpace.screenToWorld puts a lantern under the pointer, always three metres from the camera.
Hold the left mouse button and move the pointer: the lantern follows it, three metres away. Scroll to zoom.
Drag an object at arm's length
#pragma lifecycle(startup, update)
const DISTANCE = 3; // metres from the cameralet lantern;
function startup() { lantern = findEntity('Lantern');}
function update() { if (!Input.mouse.isButtonPressed(MouseButton.Left)) return; const spot = CoordinateSpace.screenToWorld(Input.mouse.position(), DISTANCE); lantern.position.copy(spot);}How it works
Section titled “How it works”The script is explained step by step in Drag an object at arm’s length.
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.
DragLantern.xrproj