Learn/XR: AR and VR

XR: AR and VR

One script API for headsets, phones and the emulator in Studio. Read poses and input, place content on real surfaces and on the Earth, and test all of it at your desk.

Time12 min readLevelIntermediateUpdatedUpdated Nov 2026

01Overview

One API for Every Device

XRService is the one place a script asks where the head and hands are, what the controls are doing, and what the real world looks like. The same calls work whatever is producing the data: Studio's emulator now; PC headsets through OpenXR, Meta Quest and Android XR, phone AR (ARCore and ARKit), Apple Vision Pro and the browser later, in versions. A script written against the emulator does not change when a device arrives.

Reach it with game:GetService("XRService") in Luau. Rune uses free functions, covered under Luau and Rune below.

What Works Today

Info
Headsets and phones are not released yet

Support for real headsets and phones has not shipped. The XR emulator in Studio is how you build and test XR scripts today. Each device arrives in a later version, and it brings no change to the API on this page.

Nothing here promises a frame rate. What a device can do is reported by the device at run time, so ask with IsSupported instead of assuming.

02Units and Spaces

Meters in World Space

Every position a script receives from XRService is in world space and in the engine's own unit, meters, the same as every part. A Luau script written for Roblox reads studs instead, as it does for every other length. Devices report real meters in their own tracking space; Eustress converts once, so a hand pose can be assigned straight to a part's CFrame.

Origin and OriginAnchor

Origin (a CFrame, read and write) says where the tracking space sits in the world. Move it to teleport the player; the headset and hands move with it. Until a script sets it, it sits on the floor under the Play camera: set when the session starts, and moved once more when the character's camera arrives a moment into Play.

OriginAnchor (an XRAnchor or nil, read and write) ties the origin to a real-world anchor. While it is set, Origin follows that anchor, so when AR tracking corrects its drift, the whole Space moves with it and stays put in the room.

WorldScale and ScaleMode

WorldScale is the real meters shown per world meter. 1 is life size. 0.02 is a tabletop: one real meter shows 50 meters of world. It scales the player's rig only. Physics and scripts keep working in world meters.

ScaleModeWorldScaleUse
TabletopYours to setThe Space shrunk onto a surface, such as a table in AR
LifeSizeForced to 1The Space at real size around the player
GeoForced to 1Real size, held at the Space's place on Earth (a later version)

TrackingOrigin (Floor, EyeLevel or Unbounded) asks the device where its own zero sits: on the floor for standing play, at head height for seated play, or unbounded for phone AR and large areas.

03Poses

GetPose and GetAimPose

GetPose(Enum.XRNode.Head) returns two values: a CFrame and a boolean that is true while the device is tracking it. The nodes are Head, LeftHand and RightHand. A hand pose is the controller grip, or the tracked wrist when there is no controller. An untracked pose is the last one known.

GetAimPose(hand) returns the pointing ray for a hand in the same two-value form. Its LookVector is the direction of the ray.

Hand Joints

GetHandJoints(hand) returns a table of 26 CFrame values in OpenXR order: palm, wrist, four thumb joints, then five for each finger. The table is empty when the hand is not hand-tracked, so check its length before indexing it.

Handheld Devices

FormFactor is Headset, Handheld or Emulated. A Handheld device is a phone or tablet: it has no hands or controllers, and touch is the input. On a Handheld device GetPose for a hand returns an identity CFrame and false, and GetInput returns 0. Write the touch path with HitTest(screenPoint) (see AR).

04Input

GetInput

GetInput(hand, name) returns the current value of one control.

NameReturnsNotes
Triggernumber, 0 to 1How far the trigger is squeezed
Gripnumber, 0 to 1How far the grip is squeezed
ThumbstickVector2Each axis from -1 to 1; never begins or ends
A, B0 or 1Right hand: lower and upper face buttons
X, Y0 or 1Left hand: lower and upper face buttons
Menu0 or 1The menu button
ThumbstickPress0 or 1Clicking the thumbstick in

InputBegan and InputEnded fire when a trigger or grip crosses 0.5, and when a button changes.

Haptic

Haptic(hand, amplitude, seconds) pulses the controller: an amplitude from 0 to 1 for a number of seconds. On a phone it maps to the vibration motor. Check IsSupported("Haptics") first when the pulse matters.

05Events

The Seven Events

EventArgumentsFires when
SessionStartedmodeAn XR session begins
SessionEndednoneThe session ends
InputBeganhand, nameA control is pressed, or a trigger or grip passes 0.5
InputEndedhand, nameThe control is released
TrackingChangednode, trackedThe head or a hand gains or loses tracking
PlaneAddedplaneThe device detects a surface
PlaneRemovedplaneA surface is no longer reported

These are the seven events of XRService in Luau; connect with :Connect. An anchor's change of state is not a service event in Luau: it shows as XRAnchor.TrackingState changing. Rune reads all eight kinds (these seven and the anchor state change) with xr_service_events() and as the xr.* topics on the event bus (see Luau and Rune).

06AR

IsSupported

IsSupported(feature) returns whether the running device offers a feature. The device reports this at run time; there is no table of devices. The names are HandTracking, Passthrough, Anchors, PlaneDetection, HitTest, Haptics and EyeTracking, plus Geo for geo anchors.

Planes

Where the device detects surfaces, it creates read-only XRPlane instances under XRService. Each has a CFrame, a Size (Vector2) and a Classification: Floor, Wall, Ceiling, Table or Unknown. Table appears only where the runtime tells a table from a floor. ARCore reports upward, downward and vertical surfaces only, so there you get Floor, Ceiling, Wall and Unknown.

Hit Tests

HitTest(origin, direction) casts a ray in world space against the real surfaces the device knows. HitTest(screenPoint) takes a Vector2 screen pixel instead, which is the call for a phone's touch. Both return a table with Position, Normal and Plane, or nil when nothing was hit.

Anchors

CreateAnchor(cframe) asks the device to hold a point in the real world and returns an XRAnchor. The anchor is an instance: its CFrame is read-only, its AnchorId is a string. Children parented to it do not follow it yet (that arrives with phone AR); place them from its CFrame.

TrackingState is Tracking (the pose is current), Limited (the device has not resolved it yet, or it is drifting) or Lost (the pose is the last one known). A new anchor starts Limited.

Passthrough

PassthroughEnabled (read and write) shows the device camera behind the Space, for phone AR and for headsets with color passthrough. It is ignored where the device cannot do it, so check IsSupported("Passthrough").

07Geo

Info
A later version

Geo comes in a later XR version. It needs a device that localizes against the Earth, which the emulator does not.

Geo Anchors

CreateGeoAnchor(latitude, longitude, altitude, headingDegrees, altitudeMode) places an anchor at a latitude and longitude. Heading and altitude mode are optional. The altitude mode is Ellipsoid (meters above the WGS84 ellipsoid, the default), Terrain or Rooftop; the last two only where the runtime knows the terrain or the buildings. The anchor stays Limited until the runtime resolves it, and its Geo field holds the latitude, longitude, altitude and altitude mode.

GetGeoPose

GetGeoPose() returns where the device is on Earth and how sure it is, or nil until it has localized:

FieldUnit
Latitude, LongitudeDegrees
AltitudeMeters
HeadingDegrees
HorizontalAccuracy, VerticalAccuracyMeters
HeadingAccuracyDegrees

Gate Geo placement on the accuracy fields: place content only once the numbers are small enough for what you are showing.

The Space on Earth

A Space's place on Earth is written once, in the Space's geo.toml:

KeyMeaning
origin_lat, origin_lonWhere the Space's origin is, in degrees
origin_altMeters above the WGS84 ellipsoid; 0 if absent
north_headingDegrees clockwise from true north that world -Z faces; 0 if absent

With north_heading 0, world -Z points to true north. With 90, -Z points east, and north is world -X. In Geo mode the device anchors the Space's origin at that point and sets OriginAnchor to it.

08The Studio Emulator

What It Is

The emulator is a fake headset and two controllers in the Studio viewport during Play, for people without a headset. It answers every call on this page the way a device would: Mode and FormFactor read as Emulated, Runtime reads as Emulator, poses move when you move the fake devices, and input events fire when you press a fake control.

Using It

  1. Turn on the toolbar's XR Emulator toggle.
  2. Press Play.
  3. Move the fake head and controllers and press their controls. The controls are listed in Studio's emulator panel.

Because the emulator is a producer like any other, a script written against it moves to a device unchanged. Ask IsSupported before using a feature, since each producer reports what it can do.

09Luau and Rune

Luau

Luau accepts both call styles: XRService:GetPose(Enum.XRNode.Head) and XRService.GetPose(Enum.XRNode.Head). Strings work where an enum item is expected, so "Head" is the same as Enum.XRNode.Head. This script points a part along the right hand's aim ray while the trigger is held:

Luau
local RunService = game:GetService("RunService")
local XRService = game:GetService("XRService")

local pointer = workspace.Pointer

RunService.Heartbeat:Connect(function()
    local held = XRService:GetInput(Enum.XRNode.RightHand, "Trigger") > 0.5
    local aim, tracked = XRService:GetAimPose(Enum.XRNode.RightHand)
    if held and tracked then
        -- Two meters along the ray, facing the way it points.
        pointer.CFrame = aim * CFrame.new(0, 0, -2)
    end
end)

Rune

Rune has no service objects, so XR is a set of free functions named for the Luau member in snake case with an xr_service_ prefix: xr_service_get_pose("Head"), xr_service_get_input("RightHand", "Trigger"), xr_service_haptic("RightHand", 0.3, 0.05), xr_service_enabled() and so on. Import what you call with use eustress::{...}. Node, input, feature and mode names are strings spelled as in Luau, and an unknown name returns an error that lists the valid ones. Poses are CFrames in world meters. Properties become a getter and a setter: xr_service_get_world_scale() and xr_service_set_world_scale(0.02). Anchors are the integer key that xr_service_create_anchor(cframe) returns; read one with xr_service_anchor_cframe(key) and xr_service_anchor_state(key). Rune has no Vector2, so xr_service_get_thumbstick(hand) returns a Vector3 with z at 0.

Writes (haptics, recenter, anchors, origin, scale, passthrough) take effect from a running Play session, in on_update and the other script hooks, and are refused anywhere else.

Events fire on the event bus as topics: xr.session_started, xr.session_ended, xr.input_began, xr.input_ended, xr.tracking_changed, xr.plane_added, xr.plane_removed and xr.anchor_state_changed. A Rune script reads the events of the current frame with xr_service_events(), which lists each event with its topic and the fields it carries (mode, node, input, tracked, id, key, state). A Rune script runs its on_update(dt) function every frame. This script pulses the right controller while the trigger is held, and again when the A button goes down:

Rune
use eustress::{xr_service_events, xr_service_get_input, xr_service_haptic};

pub fn on_update(dt) {
    if xr_service_get_input("RightHand", "Trigger").unwrap() > 0.5 {
        xr_service_haptic("RightHand", 0.3, 0.05).unwrap();
    }

    for event in xr_service_events() {
        if event.topic == "xr.input_began" && event.node == "RightHand" && event.input == "A" {
            xr_service_haptic("RightHand", 1.0, 0.1).unwrap();
        }
    }
}

10MCP

The XR Tools

An SI agent can read XR state and drive the emulator through the Eustress MCP server. These tools ship in the same release as the emulator. The two reads work at any time; the pose and input tools take hold only while the emulator is on, and a session exists only during Play:

ToolWhat it does
xr_stateReads the session, the world poses of the head and hands in world meters, their controls, the settings and the emulator's held values
xr_anchorsLists the anchors and detected planes, with their tracking state and world poses
xr_emulatorTurns the XR emulator on or off, the toolbar toggle; while on, Play runs an emulated session
xr_set_poseHolds the emulator's head or a controller at a world pose in meters; clear gives it back
xr_inputHolds a fake control on a hand, such as a trigger squeeze or the A button; clear releases it
xr_passthroughTurns passthrough on or off in the running Play session

With these, an agent can write an XR script, drive the emulator through the input the script expects, and read back what the script did, without a person wearing anything. See the MCP guide for how the server is reached.

Build it at your desk. The device comes later.

Loading Eustress Engine...