Log inGet started

xr

Updated November 24, 2026

The tracked devices of an XR session and the hand controllers: where each part of the person is, what the controllers' sticks, triggers and buttons read, what they point at, vibration, and the comfort settings of the person wearing the headset.

require("@builtin::modules.api.engine.xr") -- xr (also available as global 'xr')

The xr namespace: 122 functions.

globals/xr/aim

xr.aim() -> CameraAim

Where the game camera faces in a headset: "head" by default, or "controller".

Returns CameraAim — The aim source.

print(xr.aim())

globals/xr/body

xr.body() -> Body?

The local player's body and how the engine found it, in order: the avatar the spawn system bound to the player (avatar), the entity the game's camera follows (cameraFollow), the entity the player's character controller moves (controller), whichever the game uses: the game's camera follows it or a character controller the local player drives moves it. The eyes sit in this body while the perspective is "embodied". Nil when the game has no body to find (a game that plays from its own fixed camera, a strategy or top-down camera over many units), where the game's camera is the view. Found while a session draws frames in play mode.

Returns Body? — { entity, reason }, or nil at the floor.

local body = xr.body(); if body then print(body.entity, body.reason) end

globals/xr/controller

xr.controller(hand: Hand) -> Controller?

What a hand controller's inputs read as of the frame last drawn. A hand tracked without a controller is active, and its trigger is its pinch (1 while held). The sticks run -1 to 1 with y positive pushed away from the person; trigger and squeeze run 0 to 1. primary is A on the right controller and X on the left, secondary is B and Y, and menu is the left controller's menu button. Where the controller is comes from xr.pose(hand).

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns Controller? — The controller's inputs, or nil while no session holds input focus.

local c = xr.controller("right_hand"); if c and c.trigger > 0.8 then fire() end

globals/xr/dominantHand

xr.dominantHand() -> Hand

The role of the hand whose controller points: "right_hand" by default.

Returns Hand — The dominant hand.

print(xr.dominantHand())

globals/xr/enter

xr.enter()

Start a session now, on the active runtime, starting the runtime when it is not running: what the VR button does. On an engine whose policy is "off" it does nothing. The person's to do: a call from world or agent code raises.

xr.enter()

globals/xr/entry

xr.entry() -> Entry

How this engine comes to draw to a headset: its policy ("off", "auto" or "always"), whether an OpenXR runtime is installed, its runtime name and kind, whether it is running, and whether the person left VR (declined).

Returns Entry — The entry.

local e = xr.entry(); if e.installed and e.running ~= "running" then print("the VR button starts", e.runtime) end

globals/xr/exit

xr.exit()

Leave VR: the session ends on the next frame. On an engine with a flat view to return to (xr.returnsToFlat()) the window or the page is the view again, and the engine does not enter VR by itself again until xr.enter() or the runtime starts anew; on a standalone headset app the runtime ends the app, as the headset's own Quit does. The person's to do: a call from world or agent code raises.

xr.exit()

globals/xr/fade

xr.fade(opacity: number, seconds: number?, color: { number }?)

Run the veil over the person's whole view toward opacity (0 open, 1 closed) over seconds, in color ({ r, g, b }, 0..1). The world panels stay readable over it, so a world can be taken down behind a closed view while a panel says what comes next.

Parameters

  • opacity number — 0 (open) to 1 (closed).
  • seconds number (optional) — How long the fade runs; 0 when omitted.
  • color { number } (optional) — { r, g, b }; the colour the veil has when omitted.
xr.fade(1, 0.35)

globals/xr/fadeState

xr.fadeState() -> Fade

The veil now: its opacity, the target it runs to, whether it has arrived (done), its color and how many fades were asked for.

Returns Fade — The fade.

if xr.fadeState().done then print("arrived") end

globals/xr/focused

xr.focused() -> boolean

Whether an XR session holds input focus, which is when the hand controllers drive the game's input. False with no session, while the system menu holds input, and while the headset is not worn.

Returns boolean — True while controller input flows.

if xr.focused() then showHandHints() end

globals/xr/gestures

xr.gestures() -> Gestures

What the gestures of the bare hands read. The left palm facing the person with a pinch holds the menu button (xr.controller("left_hand").menu), a right-hand pinch-flick to the left or the right is one snap turn, and the left hand pointing with a pinch held aims a teleport that lands when the pinch opens. A pinch with the laser on an object grips it in the editor. Hand tracking drives the gestures; a hand holding a controller makes none.

Returns Gestures — The gestures.

local g = xr.gestures(); if g.teleport.aiming then print(g.teleport.seconds) end

globals/xr/hand

xr.hand(hand: Hand) -> HandPose?

The pose of a driven hand: its palm in world space and the direction each finger bone points along in the palm's frame, with its pinch and where its aim comes from. A controller's hand is modelled around its grip.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandPose? — The hand's pose, or nil while nothing drives the hand.

local pose = xr.hand("left_hand"); if pose and pose.pinching then grab() end

globals/xr/handSource

xr.handSource(hand: Hand) -> HandSource

What drives a hand now: "controller" while a controller is held in it, "hand_tracking" while the runtime tracks the bare hand, "none" otherwise and while no session holds input focus.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandSource — The source.

if xr.handSource("right_hand") == "hand_tracking" then showPinchHint() end

globals/xr/handTracking

xr.handTracking() -> HandTracking

What the runtime offers for tracking bare hands. Where it offers none, reason says why and the controllers are the only hands.

Returns HandTracking — The hand tracking status.

if not xr.handTracking().available then print(xr.handTracking().reason) end

globals/xr/joints

xr.joints(hand: Hand) -> HandJoints?

The 26 joints of a driven hand in world space, by name. They are the runtime's wherever it locates the hand (modelled false) and the model's around the controller's grip otherwise (modelled true).

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandJoints? — The joints, or nil while nothing drives the hand.

local tip = xr.joints("right_hand").joints.index_tip.position

globals/xr/panels/autoHud

xr.panels.autoHud(enabled: boolean?) -> boolean

Whether the engine shows the world's HUD on the panel "hud". Pass a boolean to turn that off or on.

Parameters

  • enabled boolean (optional) — Choose whether the HUD panel is made.

Returns boolean — Whether it is on.

xr.panels.autoHud(false)

globals/xr/panels/create

xr.panels.create(description: PanelDescription)

Make a panel. screens lists the screens it shows, or space names a space whose shown screens it shows; width and height are metres; curve is the radius in metres of the cylinder it is bent around (0 is flat); pose is where it stands, in the anchor space ("world"; "tracking" for a pose fixed to the room that follows the rig when the game moves or turns the player; or "view" for a pose in the frame at the head turned by the head's yaw and pitch and not its roll, so the panel stands that far in front of where the person looks, easing towards that place with a time constant of 0.12 seconds and standing there at once on a recenter, when the session begins and when a script states its pose or anchor); handle is { left, top, right, bottom } in the panel's uv (0,0 top left): a press there reaches the panel's UI like any press, and holds the panel once the laser has turned more than 6 degrees from where the press began with the trigger held; the panel then follows the laser until the trigger is released, turning to face the person, and the stick pulls and pushes it. A press on the handle that is released before the laser turned that far is a click, counted in the state's taps. resize makes a flat panel resizable: the trigger pulled on a corner's zone drags that corner with the laser while the opposite corner stays, within the stated minimum and maximum size, and the panel keeps its points per metre, so a larger panel lays out more content. passThrough lets the laser through a panel except over something its UI can act on. keepsFocus leaves the keys where they are when the panel is pressed: a text field holding the caret on another panel keeps it while this panel's UI is used, the way an on-screen keyboard is; a press on any other panel, or away from every panel, takes the caret from that field. order stacks panels that overlap: a panel of a higher order is drawn over one of a lower order and takes the laser wherever it covers it, whatever their distances, and of panels of one order the nearer takes the laser. A modal panel stands alone: while it is visible, every panel of a lower order is neither drawn nor pointed at. Raises when a field is invalid or the id is taken.

Parameters

  • description PanelDescription — The panel's id and fields.
xr.panels.create({ id = "stats", screens = { "stats_hud" }, width = 1.2, height = 0.7, pose = xr.panels.placement({ distance = 1.2 }), anchor = "tracking" })

globals/xr/panels/drag

xr.panels.drag() -> PanelDrag?

The UI drag in flight on the panels: a widget with a dragPayload that the trigger pulled. It reads the panel whose UI holds the drag, the payload the source declared, the label its ghost reads, whether the laser points at a panel now (overPanel) and the pointing hand. The reading holds for as long as the trigger is held, wherever the laser points, and is nil after the release, so a script places what the payload names where the laser points at the world. A drag in the window reads through ui.dragState().

Returns PanelDrag? — The drag, or nil when no panel's UI holds one.

local d = xr.panels.drag(); if d and not d.overPanel then print("carrying", d.payload) end

globals/xr/panels/grab

xr.panels.grab(id: string, options: PanelGrabOptions?)

Hold a panel with the pointing hand, which must be holding its trigger: the panel follows the laser distance metres along it (default 0.8), its centre offset from the held point in the panel's own axes, turning to face the person, until the trigger is released; the stick pulls and pushes it. A press the hand began on another panel ends there without a click. This is how a panel made from a press on a widget (an entry in a list) is dragged out and placed where the trigger is released. Raises when no panel has the id, the trigger is not held, or a panel is already held.

Parameters

  • id string — The panel's id.
  • options PanelGrabOptions (optional) — { distance?, offset? }.
xr.panels.grab("console", { distance = 0.8, offset = { x = 0, y = -0.2, z = 0 } })

globals/xr/panels/hover

xr.panels.hover() -> PanelHover?

The panel the laser points at: its id, the uv on it (0,0 is the top left), the distance along the laser, whether it is on the panel's grab handle (onHandle) or a resize corner (onCorner), and the point in the world.

Returns PanelHover? — The hover, or nil when the laser points at no panel.

local h = xr.panels.hover(); if h then print(h.id, h.uv.u) end

globals/xr/panels/list

xr.panels.list() -> { PanelDescription }

Every panel's description, in the order the panels were made.

Returns { PanelDescription } — The descriptions, each with the texture size of its picture in pixels.

for _, panel in xr.panels.list() do print(panel.id, panel.width, panel.height) end

globals/xr/panels/placement

xr.panels.placement(options: PanelPlacementOptions?) -> Pose?

A pose for a "tracking" anchored panel in front of the person: distance metres ahead (default 1.5), drop metres below eye height (default 0.15), turned yaw degrees to the left (default 0), facing the person. from names the head it is measured from: "recenter" (the default), the head as it stood when the view was last recentered, or "head", the head as it stands now. With atPointer = true the pose is distance metres along the laser instead, facing the person.

Parameters

  • options PanelPlacementOptions (optional) — { distance?, drop?, yaw?, from?, atPointer? }.

Returns Pose? — The pose, or nil until the first frame has been drawn, and with atPointer while nothing points.

local pose = xr.panels.placement({ distance = 1.2, yaw = 25 })

globals/xr/panels/remove

xr.panels.remove(id: string) -> boolean

Remove a panel.

Parameters

  • id string — The panel's id.

Returns boolean — Whether a panel was removed.

xr.panels.remove("stats")

globals/xr/panels/state

xr.panels.state(id: string) -> PanelState?

What the laser and the hand are doing with a panel: whether it is world (the pose the panel is drawn at in the world, nil before the first frame has been routed and, for a panel anchored to the view, until a frame that located the head has placed it), hovered (with the uv and distance of the laser on it), whether the laser is onHandle, whether it is grabbed, how many grabs have ended (grabs), how many presses on the handle ended as a click (taps), the turn in degrees that makes a press on the handle a grab (grabAngle), how many degrees the laser has turned since the press held on the panel began (pressTurn, nil while none is held), whether the laser is on a resize corner (onCorner) or a resize is running (resizing, with resizes counting those that ended), the panel the laser pointed at when the last grab ended (droppedOn), dropTarget, true while another panel is held and the laser points at this one, and covered, true while a visible modal panel of a higher order leaves this one undrawn.

Parameters

  • id string — The panel's id.

Returns PanelState? — The state, or nil when no panel has the id.

local s = xr.panels.state("dock"); if s and s.hovered then print(s.uv.u, s.uv.v) end

globals/xr/panels/update

xr.panels.update(id: string, fields: PanelFields)

Change fields of a panel. A field that is invalid raises and leaves the panel as it was.

Parameters

  • id string — The panel's id.
  • fields PanelFields — The fields to change; those of xr.panels.create.
xr.panels.update("stats", { visible = false })

globals/xr/perspective

xr.perspective() -> Perspective

What the person sees from in a headset: "embodied" seats the eyes in the local player's body (at its head height, over its root, the real head free on top, the body's head hidden from the eyes alone and its arms following the hands), and "game" shows the game's own camera with the head free. A world whose camera is first person is embodied; a world with no body to find shows the game's camera; any other world is embodied unless the person chose otherwise. The right thumbstick's click switches.

Returns Perspective — The perspective in force.

if xr.perspective() == "embodied" then print("in the body") end

globals/xr/perspectiveStatus

xr.perspectiveStatus() -> PerspectiveStatus

Everything about the perspective: the one in force, the kept choice, whether the person can choose, why it is what it is, the body found, where the eyes stand, and how much of the body is hidden from the eyes or reaching for the hands.

Returns PerspectiveStatus — The status.

print(xr.perspectiveStatus().why)

globals/xr/pointerRay

xr.pointerRay() -> PointerRay?

The ray the person points along, in world space: the aim pose of the dominant hand, or of the other hand while the dominant one cannot be located. The engine's pointer hit (getPointerHitTable(), what a mouse hover resolves on desktop) is cast along this ray while the session holds input focus, and the game's mouse (input.snapshot().mouse_position) is the point it rests on, seen from the game's camera; screenToRay at that position returns this ray.

Returns PointerRay? — { role, origin, direction }, or nil while no session holds input focus.

local ray = xr.pointerRay(); if ray then print(ray.role, ray.origin.x) end

globals/xr/pose

xr.pose(role: Role, kind: PoseKind?) -> Pose?

The pose of the device holding role, in world space, as of the frame last drawn: position in metres and rotation a quaternion. The pose passes through the same rig as the eyes, so it moves and turns with the game's camera. For a hand it is where the hand holds the controller, and kind "aim" is where the controller points, along its -Z axis.

Parameters

  • role Role — "head", "left_hand" or "right_hand".
  • kind PoseKind (optional) — "pose" (the default) or "aim".

Returns Pose? — The pose, or nil while the role's device is untracked or has no such pose.

local head = xr.pose("head"); if head then print(head.position.y) end
local aim = xr.pose("right_hand", "aim")

globals/xr/pulse

xr.pulse(hand: Hand, amplitude: number, seconds: number, frequency: number?) -> boolean

Vibrate a hand controller. The pulse plays on the next frame. A request that is not a valid pulse raises; one that cannot play because no session holds input focus (or too many pulses are waiting) returns false and plays nothing.

Parameters

  • hand Hand — "left_hand" or "right_hand".
  • amplitude number — Strength, 0 to 1.
  • seconds number — Length in seconds, above 0 and up to 10.
  • frequency number (optional) — Hertz; 0 or nil lets the runtime choose.

Returns boolean — Whether the pulse was accepted.

xr.pulse("right_hand", 0.6, 0.1) -- a short tap on the right hand

globals/xr/recenter

xr.recenter()

Centre the headset's world on where the person stands and faces now, on the next frame drawn; xr.recenters() rises by one.

xr.recenter()

globals/xr/returnsToFlat

xr.returnsToFlat() -> boolean

Whether this engine has a flat view to return to when its session ends: a desktop window or a browser page. A standalone headset app (the Android engine in a headset) has none, so its menus offer Quit where a desktop offers Exit VR.

Returns boolean — True with a window or a page behind the headset.

if xr.returnsToFlat() then print("Exit VR goes back to the window") end

globals/xr/roles

xr.roles() -> { Role }

The roles whose tracked device the runtime locates now, in the order "head", "left_hand", "right_hand". The head is listed while a session draws frames; a hand is listed while the session holds input focus and its controller is located.

Returns { Role } — Array of role names; empty with no session.

for _, role in xr.roles() do print(role) end

globals/xr/setAim

xr.setAim(aim: CameraAim) -> CameraAim

Choose where the game camera faces in a headset. "head" faces where the head does; "controller" faces along the dominant hand's aim direction with the head's up, so a game that aims, picks up or prompts along its camera's forward does it where the controller points. A setting of this client (xr.aim in the client settings): it holds across scene loads and applies on the next frame.

Parameters

  • aim CameraAim — "head" or "controller".

Returns CameraAim — The canonical spelling of the aim now in force.

xr.setAim("controller")

globals/xr/setDominantHand

xr.setDominantHand(hand: Hand) -> Hand

Choose the hand whose controller points. A setting of this client: it holds across scene loads.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns Hand — The canonical spelling of the hand now in force.

xr.setDominantHand("left_hand")

globals/xr/setPerspective

xr.setPerspective(perspective: Perspective) -> Perspective

Choose what the person sees from: the person's client setting xr.perspective, the same in every world. A first-person world stays embodied and a world with no body stays on the game's camera; the choice is kept and applies where it can. The choice is the person's, made in the client settings or by the right thumbstick's click: a call from world code raises, and a world reads the choice with xr.perspective().

Parameters

  • perspective Perspective — "embodied" or "game".

Returns Perspective — The perspective in force after the call.

xr.setPerspective("game")

globals/xr/setPointerReach

xr.setPointerReach(distance: number?)

Say how far along the pointer ray the laser is drawn while a script carries something to a point the engine's own cast does not know of (an asset held under the laser): the beam ends distance metres out. The laser over a panel still ends on the panel. Call it each frame it applies; nil hands the beam back to the engine's cast.

Parameters

  • distance number (optional) — Metres along the ray, above 0, or nil.
xr.setPointerReach(where.distance)

globals/xr/setSnapTurnDegrees

xr.setSnapTurnDegrees(degrees: number) -> number

Choose the angle one snap-turn step turns the view by, held to 10..180 degrees. The client settings apply the person's snap angle through it.

Parameters

  • degrees number — Degrees per step.

Returns number — The angle now in force.

xr.setSnapTurnDegrees(30)

globals/xr/setTurnMode

xr.setTurnMode(mode: TurnMode) -> TurnMode

Choose how the right stick turns the view in a headset. A comfort setting of this client: it holds across scene loads, and a settings screen offering it is this call.

Parameters

  • mode TurnMode — "snap" or "smooth".

Returns TurnMode — The canonical spelling of the mode now in force.

xr.setTurnMode("smooth")

globals/xr/setVignette

xr.setVignette(strength: number) -> number

Choose how dark the comfort vignette grows while the game moves the person. A comfort setting of this client.

Parameters

  • strength number — 0 (none) to 1.

Returns number — The strength now in force.

xr.setVignette(0.5)

globals/xr/snapTurnDegrees

xr.snapTurnDegrees() -> number

The angle one snap-turn step turns the view by, in degrees: the person's snap angle (client setting xr.snapAngle), 45 by default.

Returns number — Degrees per step.

print(xr.snapTurnDegrees())

globals/xr/tracked

xr.tracked(role: Role) -> boolean

Whether the runtime locates the device holding role now.

Parameters

  • role Role — "head", "left_hand" or "right_hand".

Returns boolean — True while the role's device is located.

if xr.tracked("left_hand") then showLeftHandHint() end

globals/xr/turnMode

xr.turnMode() -> TurnMode

How the right stick turns the view in a headset. "snap" (the default) turns by one step of xr.snapTurnDegrees() per flick of the stick; "smooth" turns continuously in proportion to the stick's deflection. Either way the game turns its own camera through its look action and the headset follows the camera's yaw; the stick never tilts the view, because the head owns pitch.

Returns TurnMode — The turn mode.

print(xr.turnMode())

globals/xr/vignette

xr.vignette() -> number

How dark the comfort vignette grows at the edge of the view while the game moves or turns the person, 0 (none) to 1. How much of it shows follows how fast the person is moved or turned; a snap turn or a cut darkens nothing.

Returns number — The strength.

print(xr.vignette())

modules/xr/aim

aim(): CameraAim

Where the game camera faces in a headset: "head" by default, or "controller".

print(xr.aim())

modules/xr/body

body(): Body?

The local player's body and how the engine found it, in order: the avatar the spawn system bound to the player (avatar), the entity the game's camera follows (cameraFollow), the entity the player's character controller moves (controller), whichever the game uses: the game's camera follows it or a character controller the local player drives moves it. The eyes sit in this body while the perspective is "embodied". Nil when the game has no body to find (a game that plays from its own fixed camera, a strategy or top-down camera over many units), where the game's camera is the view. Found while a session draws frames in play mode.

local body = xr.body(); if body then print(body.entity, body.reason) end

modules/xr/controller

controller(hand: Hand): Controller?

What a hand controller's inputs read as of the frame last drawn. A hand tracked without a controller is active, and its trigger is its pinch (1 while held). The sticks run -1 to 1 with y positive pushed away from the person; trigger and squeeze run 0 to 1. primary is A on the right controller and X on the left, secondary is B and Y, and menu is the left controller's menu button. Where the controller is comes from xr.pose(hand).

Parameters

  • hand Hand — "left_hand" or "right_hand".
local c = xr.controller("right_hand"); if c and c.trigger > 0.8 then fire() end

modules/xr/dominantHand

dominantHand(): Hand

The role of the hand whose controller points: "right_hand" by default.

print(xr.dominantHand())

modules/xr/enter

enter()

Start a session now, on the active runtime, starting the runtime when it is not running: what the VR button does. On an engine whose policy is "off" it does nothing. The person's to do: a call from world or agent code raises.

xr.enter()

modules/xr/entry

entry(): Entry

How this engine comes to draw to a headset: its policy ("off", "auto" or "always"), whether an OpenXR runtime is installed, its runtime name and kind, whether it is running, and whether the person left VR (declined).

local e = xr.entry(); if e.installed and e.running ~= "running" then print("the VR button starts", e.runtime) end

modules/xr/exit

exit()

Leave VR: the session ends on the next frame. On an engine with a flat view to return to (xr.returnsToFlat()) the window or the page is the view again, and the engine does not enter VR by itself again until xr.enter() or the runtime starts anew; on a standalone headset app the runtime ends the app, as the headset's own Quit does. The person's to do: a call from world or agent code raises.

xr.exit()

modules/xr/fade

fade(opacity: number, seconds: number?, color: { number }?)

Run the veil over the person's whole view toward opacity (0 open, 1 closed) over seconds, in color ({ r, g, b }, 0..1). The world panels stay readable over it, so a world can be taken down behind a closed view while a panel says what comes next.

Parameters

  • opacity number — 0 (open) to 1 (closed).
  • seconds number? (optional) — How long the fade runs; 0 when omitted.
  • color { number }? (optional) — { r, g, b }; the colour the veil has when omitted.
xr.fade(1, 0.35)

modules/xr/fadeState

fadeState(): Fade

The veil now: its opacity, the target it runs to, whether it has arrived (done), its color and how many fades were asked for.

if xr.fadeState().done then print("arrived") end

modules/xr/focused

focused(): boolean

Whether an XR session holds input focus, which is when the hand controllers drive the game's input. False with no session, while the system menu holds input, and while the headset is not worn.

if xr.focused() then showHandHints() end

modules/xr/gestures

gestures(): Gestures

What the gestures of the bare hands read. The left palm facing the person with a pinch holds the menu button (xr.controller("left_hand").menu), a right-hand pinch-flick to the left or the right is one snap turn, and the left hand pointing with a pinch held aims a teleport that lands when the pinch opens. A pinch with the laser on an object grips it in the editor. Hand tracking drives the gestures; a hand holding a controller makes none.

local g = xr.gestures(); if g.teleport.aiming then print(g.teleport.seconds) end

modules/xr/hand

hand(hand: Hand): HandPose?

The pose of a driven hand: its palm in world space and the direction each finger bone points along in the palm's frame, with its pinch and where its aim comes from. A controller's hand is modelled around its grip.

Parameters

  • hand Hand — "left_hand" or "right_hand".
local pose = xr.hand("left_hand"); if pose and pose.pinching then grab() end

modules/xr/handSource

handSource(hand: Hand): HandSource

What drives a hand now: "controller" while a controller is held in it, "hand_tracking" while the runtime tracks the bare hand, "none" otherwise and while no session holds input focus.

Parameters

  • hand Hand — "left_hand" or "right_hand".
if xr.handSource("right_hand") == "hand_tracking" then showPinchHint() end

modules/xr/handTracking

handTracking(): HandTracking

What the runtime offers for tracking bare hands. Where it offers none, reason says why and the controllers are the only hands.

if not xr.handTracking().available then print(xr.handTracking().reason) end

modules/xr/joints

joints(hand: Hand): HandJoints?

The 26 joints of a driven hand in world space, by name. They are the runtime's wherever it locates the hand (modelled false) and the model's around the controller's grip otherwise (modelled true).

Parameters

  • hand Hand — "left_hand" or "right_hand".
local tip = xr.joints("right_hand").joints.index_tip.position

modules/xr/panels.autoHud

panels.autoHud(enabled: boolean?): boolean

Whether the engine shows the world's HUD on the panel "hud". Pass a boolean to turn that off or on.

Parameters

  • enabled boolean? (optional) — Choose whether the HUD panel is made.
xr.panels.autoHud(false)

modules/xr/panels.create

panels.create(description: PanelDescription)

Make a panel. screens lists the screens it shows, or space names a space whose shown screens it shows; width and height are metres; curve is the radius in metres of the cylinder it is bent around (0 is flat); pose is where it stands, in the anchor space ("world"; "tracking" for a pose fixed to the room that follows the rig when the game moves or turns the player; or "view" for a pose in the frame at the head turned by the head's yaw and pitch and not its roll, so the panel stands that far in front of where the person looks, easing towards that place with a time constant of 0.12 seconds and standing there at once on a recenter, when the session begins and when a script states its pose or anchor); handle is { left, top, right, bottom } in the panel's uv (0,0 top left): a press there reaches the panel's UI like any press, and holds the panel once the laser has turned more than 6 degrees from where the press began with the trigger held; the panel then follows the laser until the trigger is released, turning to face the person, and the stick pulls and pushes it. A press on the handle that is released before the laser turned that far is a click, counted in the state's taps. resize makes a flat panel resizable: the trigger pulled on a corner's zone drags that corner with the laser while the opposite corner stays, within the stated minimum and maximum size, and the panel keeps its points per metre, so a larger panel lays out more content. passThrough lets the laser through a panel except over something its UI can act on. keepsFocus leaves the keys where they are when the panel is pressed: a text field holding the caret on another panel keeps it while this panel's UI is used, the way an on-screen keyboard is; a press on any other panel, or away from every panel, takes the caret from that field. order stacks panels that overlap: a panel of a higher order is drawn over one of a lower order and takes the laser wherever it covers it, whatever their distances, and of panels of one order the nearer takes the laser. A modal panel stands alone: while it is visible, every panel of a lower order is neither drawn nor pointed at. Raises when a field is invalid or the id is taken.

Parameters

  • description PanelDescription — The panel's id and fields.
xr.panels.create({ id = "stats", screens = { "stats_hud" }, width = 1.2, height = 0.7, pose = xr.panels.placement({ distance = 1.2 }), anchor = "tracking" })

modules/xr/panels.drag

panels.drag(): PanelDrag?

The UI drag in flight on the panels: a widget with a dragPayload that the trigger pulled. It reads the panel whose UI holds the drag, the payload the source declared, the label its ghost reads, whether the laser points at a panel now (overPanel) and the pointing hand. The reading holds for as long as the trigger is held, wherever the laser points, and is nil after the release, so a script places what the payload names where the laser points at the world. A drag in the window reads through ui.dragState().

local d = xr.panels.drag(); if d and not d.overPanel then print("carrying", d.payload) end

modules/xr/panels.grab

panels.grab(id: string, options: PanelGrabOptions?)

Hold a panel with the pointing hand, which must be holding its trigger: the panel follows the laser distance metres along it (default 0.8), its centre offset from the held point in the panel's own axes, turning to face the person, until the trigger is released; the stick pulls and pushes it. A press the hand began on another panel ends there without a click. This is how a panel made from a press on a widget (an entry in a list) is dragged out and placed where the trigger is released. Raises when no panel has the id, the trigger is not held, or a panel is already held.

Parameters

  • id string — The panel's id.
  • options PanelGrabOptions? (optional) — { distance?, offset? }.
xr.panels.grab("console", { distance = 0.8, offset = { x = 0, y = -0.2, z = 0 } })

modules/xr/panels.hover

panels.hover(): PanelHover?

The panel the laser points at: its id, the uv on it (0,0 is the top left), the distance along the laser, whether it is on the panel's grab handle (onHandle) or a resize corner (onCorner), and the point in the world.

local h = xr.panels.hover(); if h then print(h.id, h.uv.u) end

modules/xr/panels.list

panels.list(): { PanelDescription }

Every panel's description, in the order the panels were made.

for _, panel in xr.panels.list() do print(panel.id, panel.width, panel.height) end

modules/xr/panels.placement

panels.placement(options: PanelPlacementOptions?): Pose?

A pose for a "tracking" anchored panel in front of the person: distance metres ahead (default 1.5), drop metres below eye height (default 0.15), turned yaw degrees to the left (default 0), facing the person. from names the head it is measured from: "recenter" (the default), the head as it stood when the view was last recentered, or "head", the head as it stands now. With atPointer = true the pose is distance metres along the laser instead, facing the person.

Parameters

  • options PanelPlacementOptions? (optional) — { distance?, drop?, yaw?, from?, atPointer? }.
local pose = xr.panels.placement({ distance = 1.2, yaw = 25 })

modules/xr/panels.remove

panels.remove(id: string): boolean

Remove a panel.

Parameters

  • id string — The panel's id.
xr.panels.remove("stats")

modules/xr/panels.state

panels.state(id: string): PanelState?

What the laser and the hand are doing with a panel: whether it is world (the pose the panel is drawn at in the world, nil before the first frame has been routed and, for a panel anchored to the view, until a frame that located the head has placed it), hovered (with the uv and distance of the laser on it), whether the laser is onHandle, whether it is grabbed, how many grabs have ended (grabs), how many presses on the handle ended as a click (taps), the turn in degrees that makes a press on the handle a grab (grabAngle), how many degrees the laser has turned since the press held on the panel began (pressTurn, nil while none is held), whether the laser is on a resize corner (onCorner) or a resize is running (resizing, with resizes counting those that ended), the panel the laser pointed at when the last grab ended (droppedOn), dropTarget, true while another panel is held and the laser points at this one, and covered, true while a visible modal panel of a higher order leaves this one undrawn.

Parameters

  • id string — The panel's id.
local s = xr.panels.state("dock"); if s and s.hovered then print(s.uv.u, s.uv.v) end

modules/xr/panels.update

panels.update(id: string, fields: PanelFields)

Change fields of a panel. A field that is invalid raises and leaves the panel as it was.

Parameters

  • id string — The panel's id.
  • fields PanelFields — The fields to change; those of xr.panels.create.
xr.panels.update("stats", { visible = false })

modules/xr/perspective

perspective(): Perspective

What the person sees from in a headset: "embodied" seats the eyes in the local player's body (at its head height, over its root, the real head free on top, the body's head hidden from the eyes alone and its arms following the hands), and "game" shows the game's own camera with the head free. A world whose camera is first person is embodied; a world with no body to find shows the game's camera; any other world is embodied unless the person chose otherwise. The right thumbstick's click switches.

if xr.perspective() == "embodied" then print("in the body") end

modules/xr/perspectiveStatus

perspectiveStatus(): PerspectiveStatus

Everything about the perspective: the one in force, the kept choice, whether the person can choose, why it is what it is, the body found, where the eyes stand, and how much of the body is hidden from the eyes or reaching for the hands.

print(xr.perspectiveStatus().why)

modules/xr/pointerRay

pointerRay(): PointerRay?

The ray the person points along, in world space: the aim pose of the dominant hand, or of the other hand while the dominant one cannot be located. The engine's pointer hit (getPointerHitTable(), what a mouse hover resolves on desktop) is cast along this ray while the session holds input focus, and the game's mouse (input.snapshot().mouse_position) is the point it rests on, seen from the game's camera; screenToRay at that position returns this ray.

local ray = xr.pointerRay(); if ray then print(ray.role, ray.origin.x) end

modules/xr/pose

pose(role: Role, kind: PoseKind?): Pose?

The pose of the device holding role, in world space, as of the frame last drawn: position in metres and rotation a quaternion. The pose passes through the same rig as the eyes, so it moves and turns with the game's camera. For a hand it is where the hand holds the controller, and kind "aim" is where the controller points, along its -Z axis.

Parameters

  • role Role — "head", "left_hand" or "right_hand".
  • kind PoseKind? (optional) — "pose" (the default) or "aim".
local head = xr.pose("head"); if head then print(head.position.y) end
local aim = xr.pose("right_hand", "aim")

modules/xr/pulse

pulse(hand: Hand, amplitude: number, seconds: number, frequency: number?): boolean

Vibrate a hand controller. The pulse plays on the next frame. A request that is not a valid pulse raises; one that cannot play because no session holds input focus (or too many pulses are waiting) returns false and plays nothing.

Parameters

  • hand Hand — "left_hand" or "right_hand".
  • amplitude number — Strength, 0 to 1.
  • seconds number — Length in seconds, above 0 and up to 10.
  • frequency number? (optional) — Hertz; 0 or nil lets the runtime choose.
xr.pulse("right_hand", 0.6, 0.1) -- a short tap on the right hand

modules/xr/recenter

recenter()

Centre the headset's world on where the person stands and faces now, on the next frame drawn; xr.recenters() rises by one.

xr.recenter()

modules/xr/returnsToFlat

returnsToFlat(): boolean

Whether this engine has a flat view to return to when its session ends: a desktop window or a browser page. A standalone headset app (the Android engine in a headset) has none, so its menus offer Quit where a desktop offers Exit VR.

if xr.returnsToFlat() then print("Exit VR goes back to the window") end

modules/xr/roles

roles(): { Role }

The roles whose tracked device the runtime locates now, in the order "head", "left_hand", "right_hand". The head is listed while a session draws frames; a hand is listed while the session holds input focus and its controller is located.

for _, role in xr.roles() do print(role) end

modules/xr/setAim

setAim(aim: CameraAim): CameraAim

Choose where the game camera faces in a headset. "head" faces where the head does; "controller" faces along the dominant hand's aim direction with the head's up, so a game that aims, picks up or prompts along its camera's forward does it where the controller points. A setting of this client (xr.aim in the client settings): it holds across scene loads and applies on the next frame.

Parameters

  • aim CameraAim — "head" or "controller".
xr.setAim("controller")

modules/xr/setDominantHand

setDominantHand(hand: Hand): Hand

Choose the hand whose controller points. A setting of this client: it holds across scene loads.

Parameters

  • hand Hand — "left_hand" or "right_hand".
xr.setDominantHand("left_hand")

modules/xr/setPerspective

setPerspective(perspective: Perspective): Perspective

Choose what the person sees from: the person's client setting xr.perspective, the same in every world. A first-person world stays embodied and a world with no body stays on the game's camera; the choice is kept and applies where it can. The choice is the person's, made in the client settings or by the right thumbstick's click: a call from world code raises, and a world reads the choice with xr.perspective().

Parameters

  • perspective Perspective — "embodied" or "game".
xr.setPerspective("game")

modules/xr/setPointerReach

setPointerReach(distance: number?)

Say how far along the pointer ray the laser is drawn while a script carries something to a point the engine's own cast does not know of (an asset held under the laser): the beam ends distance metres out. The laser over a panel still ends on the panel. Call it each frame it applies; nil hands the beam back to the engine's cast.

Parameters

  • distance number? (optional) — Metres along the ray, above 0, or nil.
xr.setPointerReach(where.distance)

modules/xr/setSnapTurnDegrees

setSnapTurnDegrees(degrees: number): number

Choose the angle one snap-turn step turns the view by, held to 10..180 degrees. The client settings apply the person's snap angle through it.

Parameters

  • degrees number — Degrees per step.
xr.setSnapTurnDegrees(30)

modules/xr/setTurnMode

setTurnMode(mode: TurnMode): TurnMode

Choose how the right stick turns the view in a headset. A comfort setting of this client: it holds across scene loads, and a settings screen offering it is this call.

Parameters

  • mode TurnMode — "snap" or "smooth".
xr.setTurnMode("smooth")

modules/xr/setVignette

setVignette(strength: number): number

Choose how dark the comfort vignette grows while the game moves the person. A comfort setting of this client.

Parameters

  • strength number — 0 (none) to 1.
xr.setVignette(0.5)

modules/xr/snapTurnDegrees

snapTurnDegrees(): number

The angle one snap-turn step turns the view by, in degrees: the person's snap angle (client setting xr.snapAngle), 45 by default.

print(xr.snapTurnDegrees())

modules/xr/tracked

tracked(role: Role): boolean

Whether the runtime locates the device holding role now.

Parameters

  • role Role — "head", "left_hand" or "right_hand".
if xr.tracked("left_hand") then showLeftHandHint() end

modules/xr/turnMode

turnMode(): TurnMode

How the right stick turns the view in a headset. "snap" (the default) turns by one step of xr.snapTurnDegrees() per flick of the stick; "smooth" turns continuously in proportion to the stick's deflection. Either way the game turns its own camera through its look action and the headset follows the camera's yaw; the stick never tilts the view, because the head owns pitch.

print(xr.turnMode())

modules/xr/vignette

vignette(): number

How dark the comfort vignette grows at the edge of the view while the game moves or turns the person, 0 (none) to 1. How much of it shows follows how fast the person is moved or turned; a snap turn or a cut darkens nothing.

print(xr.vignette())

typed/builtin//modules/api/engine/xr/xr/aim

xr.aim() -> CameraAim

Where the game camera faces in a headset: "head" by default, or "controller".

Returns CameraAim — The aim source.

print(xr.aim())

typed/builtin//modules/api/engine/xr/xr/body

xr.body() -> Body?

The local player's body and how the engine found it, in order: the avatar the spawn system bound to the player (avatar), the entity the game's camera follows (cameraFollow), the entity the player's character controller moves (controller), whichever the game uses: the game's camera follows it or a character controller the local player drives moves it. The eyes sit in this body while the perspective is "embodied". Nil when the game has no body to find (a game that plays from its own fixed camera, a strategy or top-down camera over many units), where the game's camera is the view. Found while a session draws frames in play mode.

Returns Body? — { entity, reason }, or nil at the floor.

local body = xr.body(); if body then print(body.entity, body.reason) end

typed/builtin//modules/api/engine/xr/xr/controller

xr.controller(hand: Hand) -> Controller?

What a hand controller's inputs read as of the frame last drawn. A hand tracked without a controller is active, and its trigger is its pinch (1 while held). The sticks run -1 to 1 with y positive pushed away from the person; trigger and squeeze run 0 to 1. primary is A on the right controller and X on the left, secondary is B and Y, and menu is the left controller's menu button. Where the controller is comes from xr.pose(hand).

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns Controller? — The controller's inputs, or nil while no session holds input focus.

local c = xr.controller("right_hand"); if c and c.trigger > 0.8 then fire() end

typed/builtin//modules/api/engine/xr/xr/dominantHand

xr.dominantHand() -> Hand

The role of the hand whose controller points: "right_hand" by default.

Returns Hand — The dominant hand.

print(xr.dominantHand())

typed/builtin//modules/api/engine/xr/xr/enter

xr.enter()

Start a session now, on the active runtime, starting the runtime when it is not running: what the VR button does. On an engine whose policy is "off" it does nothing. The person's to do: a call from world or agent code raises.

xr.enter()

typed/builtin//modules/api/engine/xr/xr/entry

xr.entry() -> Entry

How this engine comes to draw to a headset: its policy ("off", "auto" or "always"), whether an OpenXR runtime is installed, its runtime name and kind, whether it is running, and whether the person left VR (declined).

Returns Entry — The entry.

local e = xr.entry(); if e.installed and e.running ~= "running" then print("the VR button starts", e.runtime) end

typed/builtin//modules/api/engine/xr/xr/exit

xr.exit()

Leave VR: the session ends on the next frame. On an engine with a flat view to return to (xr.returnsToFlat()) the window or the page is the view again, and the engine does not enter VR by itself again until xr.enter() or the runtime starts anew; on a standalone headset app the runtime ends the app, as the headset's own Quit does. The person's to do: a call from world or agent code raises.

xr.exit()

typed/builtin//modules/api/engine/xr/xr/fade

xr.fade(opacity: number, seconds: number?, color: { number }?)

Run the veil over the person's whole view toward opacity (0 open, 1 closed) over seconds, in color ({ r, g, b }, 0..1). The world panels stay readable over it, so a world can be taken down behind a closed view while a panel says what comes next.

Parameters

  • opacity number — 0 (open) to 1 (closed).
  • seconds number (optional) — How long the fade runs; 0 when omitted.
  • color { number } (optional) — { r, g, b }; the colour the veil has when omitted.
xr.fade(1, 0.35)

typed/builtin//modules/api/engine/xr/xr/fadeState

xr.fadeState() -> Fade

The veil now: its opacity, the target it runs to, whether it has arrived (done), its color and how many fades were asked for.

Returns Fade — The fade.

if xr.fadeState().done then print("arrived") end

typed/builtin//modules/api/engine/xr/xr/focused

xr.focused() -> boolean

Whether an XR session holds input focus, which is when the hand controllers drive the game's input. False with no session, while the system menu holds input, and while the headset is not worn.

Returns boolean — True while controller input flows.

if xr.focused() then showHandHints() end

typed/builtin//modules/api/engine/xr/xr/gestures

xr.gestures() -> Gestures

What the gestures of the bare hands read. The left palm facing the person with a pinch holds the menu button (xr.controller("left_hand").menu), a right-hand pinch-flick to the left or the right is one snap turn, and the left hand pointing with a pinch held aims a teleport that lands when the pinch opens. A pinch with the laser on an object grips it in the editor. Hand tracking drives the gestures; a hand holding a controller makes none.

Returns Gestures — The gestures.

local g = xr.gestures(); if g.teleport.aiming then print(g.teleport.seconds) end

typed/builtin//modules/api/engine/xr/xr/hand

xr.hand(hand: Hand) -> HandPose?

The pose of a driven hand: its palm in world space and the direction each finger bone points along in the palm's frame, with its pinch and where its aim comes from. A controller's hand is modelled around its grip.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandPose? — The hand's pose, or nil while nothing drives the hand.

local pose = xr.hand("left_hand"); if pose and pose.pinching then grab() end

typed/builtin//modules/api/engine/xr/xr/handSource

xr.handSource(hand: Hand) -> HandSource

What drives a hand now: "controller" while a controller is held in it, "hand_tracking" while the runtime tracks the bare hand, "none" otherwise and while no session holds input focus.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandSource — The source.

if xr.handSource("right_hand") == "hand_tracking" then showPinchHint() end

typed/builtin//modules/api/engine/xr/xr/handTracking

xr.handTracking() -> HandTracking

What the runtime offers for tracking bare hands. Where it offers none, reason says why and the controllers are the only hands.

Returns HandTracking — The hand tracking status.

if not xr.handTracking().available then print(xr.handTracking().reason) end

typed/builtin//modules/api/engine/xr/xr/joints

xr.joints(hand: Hand) -> HandJoints?

The 26 joints of a driven hand in world space, by name. They are the runtime's wherever it locates the hand (modelled false) and the model's around the controller's grip otherwise (modelled true).

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns HandJoints? — The joints, or nil while nothing drives the hand.

local tip = xr.joints("right_hand").joints.index_tip.position

typed/builtin//modules/api/engine/xr/xr/perspective

xr.perspective() -> Perspective

What the person sees from in a headset: "embodied" seats the eyes in the local player's body (at its head height, over its root, the real head free on top, the body's head hidden from the eyes alone and its arms following the hands), and "game" shows the game's own camera with the head free. A world whose camera is first person is embodied; a world with no body to find shows the game's camera; any other world is embodied unless the person chose otherwise. The right thumbstick's click switches.

Returns Perspective — The perspective in force.

if xr.perspective() == "embodied" then print("in the body") end

typed/builtin//modules/api/engine/xr/xr/perspectiveStatus

xr.perspectiveStatus() -> PerspectiveStatus

Everything about the perspective: the one in force, the kept choice, whether the person can choose, why it is what it is, the body found, where the eyes stand, and how much of the body is hidden from the eyes or reaching for the hands.

Returns PerspectiveStatus — The status.

print(xr.perspectiveStatus().why)

typed/builtin//modules/api/engine/xr/xr/pointerRay

xr.pointerRay() -> PointerRay?

The ray the person points along, in world space: the aim pose of the dominant hand, or of the other hand while the dominant one cannot be located. The engine's pointer hit (getPointerHitTable(), what a mouse hover resolves on desktop) is cast along this ray while the session holds input focus, and the game's mouse (input.snapshot().mouse_position) is the point it rests on, seen from the game's camera; screenToRay at that position returns this ray.

Returns PointerRay? — { role, origin, direction }, or nil while no session holds input focus.

local ray = xr.pointerRay(); if ray then print(ray.role, ray.origin.x) end

typed/builtin//modules/api/engine/xr/xr/pose

xr.pose(role: Role, kind: PoseKind?) -> Pose?

The pose of the device holding role, in world space, as of the frame last drawn: position in metres and rotation a quaternion. The pose passes through the same rig as the eyes, so it moves and turns with the game's camera. For a hand it is where the hand holds the controller, and kind "aim" is where the controller points, along its -Z axis.

Parameters

  • role Role — "head", "left_hand" or "right_hand".
  • kind PoseKind (optional) — "pose" (the default) or "aim".

Returns Pose? — The pose, or nil while the role's device is untracked or has no such pose.

local head = xr.pose("head"); if head then print(head.position.y) end
local aim = xr.pose("right_hand", "aim")

typed/builtin//modules/api/engine/xr/xr/pulse

xr.pulse(hand: Hand, amplitude: number, seconds: number, frequency: number?) -> boolean

Vibrate a hand controller. The pulse plays on the next frame. A request that is not a valid pulse raises; one that cannot play because no session holds input focus (or too many pulses are waiting) returns false and plays nothing.

Parameters

  • hand Hand — "left_hand" or "right_hand".
  • amplitude number — Strength, 0 to 1.
  • seconds number — Length in seconds, above 0 and up to 10.
  • frequency number (optional) — Hertz; 0 or nil lets the runtime choose.

Returns boolean — Whether the pulse was accepted.

xr.pulse("right_hand", 0.6, 0.1) -- a short tap on the right hand

typed/builtin//modules/api/engine/xr/xr/recenter

xr.recenter()

Centre the headset's world on where the person stands and faces now, on the next frame drawn; xr.recenters() rises by one.

xr.recenter()

typed/builtin//modules/api/engine/xr/xr/returnsToFlat

xr.returnsToFlat() -> boolean

Whether this engine has a flat view to return to when its session ends: a desktop window or a browser page. A standalone headset app (the Android engine in a headset) has none, so its menus offer Quit where a desktop offers Exit VR.

Returns boolean — True with a window or a page behind the headset.

if xr.returnsToFlat() then print("Exit VR goes back to the window") end

typed/builtin//modules/api/engine/xr/xr/roles

xr.roles() -> { Role }

The roles whose tracked device the runtime locates now, in the order "head", "left_hand", "right_hand". The head is listed while a session draws frames; a hand is listed while the session holds input focus and its controller is located.

Returns { Role } — Array of role names; empty with no session.

for _, role in xr.roles() do print(role) end

typed/builtin//modules/api/engine/xr/xr/setAim

xr.setAim(aim: CameraAim) -> CameraAim

Choose where the game camera faces in a headset. "head" faces where the head does; "controller" faces along the dominant hand's aim direction with the head's up, so a game that aims, picks up or prompts along its camera's forward does it where the controller points. A setting of this client (xr.aim in the client settings): it holds across scene loads and applies on the next frame.

Parameters

  • aim CameraAim — "head" or "controller".

Returns CameraAim — The canonical spelling of the aim now in force.

xr.setAim("controller")

typed/builtin//modules/api/engine/xr/xr/setDominantHand

xr.setDominantHand(hand: Hand) -> Hand

Choose the hand whose controller points. A setting of this client: it holds across scene loads.

Parameters

  • hand Hand — "left_hand" or "right_hand".

Returns Hand — The canonical spelling of the hand now in force.

xr.setDominantHand("left_hand")

typed/builtin//modules/api/engine/xr/xr/setPerspective

xr.setPerspective(perspective: Perspective) -> Perspective

Choose what the person sees from: the person's client setting xr.perspective, the same in every world. A first-person world stays embodied and a world with no body stays on the game's camera; the choice is kept and applies where it can. The choice is the person's, made in the client settings or by the right thumbstick's click: a call from world code raises, and a world reads the choice with xr.perspective().

Parameters

  • perspective Perspective — "embodied" or "game".

Returns Perspective — The perspective in force after the call.

xr.setPerspective("game")

typed/builtin//modules/api/engine/xr/xr/setPointerReach

xr.setPointerReach(distance: number?)

Say how far along the pointer ray the laser is drawn while a script carries something to a point the engine's own cast does not know of (an asset held under the laser): the beam ends distance metres out. The laser over a panel still ends on the panel. Call it each frame it applies; nil hands the beam back to the engine's cast.

Parameters

  • distance number (optional) — Metres along the ray, above 0, or nil.
xr.setPointerReach(where.distance)

typed/builtin//modules/api/engine/xr/xr/setSnapTurnDegrees

xr.setSnapTurnDegrees(degrees: number) -> number

Choose the angle one snap-turn step turns the view by, held to 10..180 degrees. The client settings apply the person's snap angle through it.

Parameters

  • degrees number — Degrees per step.

Returns number — The angle now in force.

xr.setSnapTurnDegrees(30)

typed/builtin//modules/api/engine/xr/xr/setTurnMode

xr.setTurnMode(mode: TurnMode) -> TurnMode

Choose how the right stick turns the view in a headset. A comfort setting of this client: it holds across scene loads, and a settings screen offering it is this call.

Parameters

  • mode TurnMode — "snap" or "smooth".

Returns TurnMode — The canonical spelling of the mode now in force.

xr.setTurnMode("smooth")

typed/builtin//modules/api/engine/xr/xr/setVignette

xr.setVignette(strength: number) -> number

Choose how dark the comfort vignette grows while the game moves the person. A comfort setting of this client.

Parameters

  • strength number — 0 (none) to 1.

Returns number — The strength now in force.

xr.setVignette(0.5)

typed/builtin//modules/api/engine/xr/xr/snapTurnDegrees

xr.snapTurnDegrees() -> number

The angle one snap-turn step turns the view by, in degrees: the person's snap angle (client setting xr.snapAngle), 45 by default.

Returns number — Degrees per step.

print(xr.snapTurnDegrees())

typed/builtin//modules/api/engine/xr/xr/tracked

xr.tracked(role: Role) -> boolean

Whether the runtime locates the device holding role now.

Parameters

  • role Role — "head", "left_hand" or "right_hand".

Returns boolean — True while the role's device is located.

if xr.tracked("left_hand") then showLeftHandHint() end

typed/builtin//modules/api/engine/xr/xr/turnMode

xr.turnMode() -> TurnMode

How the right stick turns the view in a headset. "snap" (the default) turns by one step of xr.snapTurnDegrees() per flick of the stick; "smooth" turns continuously in proportion to the stick's deflection. Either way the game turns its own camera through its look action and the headset follows the camera's yaw; the stick never tilts the view, because the head owns pitch.

Returns TurnMode — The turn mode.

print(xr.turnMode())

typed/builtin//modules/api/engine/xr/xr/vignette

xr.vignette() -> number

How dark the comfort vignette grows at the edge of the view while the game moves or turns the person, 0 (none) to 1. How much of it shows follows how fast the person is moved or turned; a snap turn or a cut darkens nothing.

Returns number — The strength.

print(xr.vignette())
  • api
  • reference