Click to walk there
Updated
Each click is cast onto the scene, snapped to the navmesh with closestPoint, and the hero walks there round the walls through its NavMesh Agent and Character Controller.
Click the floor to send the hero there. Drag to orbit the camera, scroll to zoom.
Click to walk there
#pragma lifecycle(startup, update)
let character;let surface;
function startup() { character = findEntity('Hero').getComponent(CharacterControllerComponent); surface = findEntity('NavMesh Surface').getComponent(NavMeshSurfaceComponent);}
function update() { if (!Input.mouse.isButtonReleased(MouseButton.Left)) return; const hit = GraphicsRaycaster.fromScreen(Input.mouse.position()).hit(); if (!hit) return; const goal = surface.closestPoint(hit.point); if (goal && !character.moveTo(goal)) log('No route there');}How it works
Section titled “How it works”The script is explained step by step in Click to walk there.
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.
ClickToWalk.xrproj