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.
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
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.
| ScaleMode | WorldScale | Use |
|---|---|---|
Tabletop | Yours to set | The Space shrunk onto a surface, such as a table in AR |
LifeSize | Forced to 1 | The Space at real size around the player |
Geo | Forced to 1 | Real 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.
| Name | Returns | Notes |
|---|---|---|
Trigger | number, 0 to 1 | How far the trigger is squeezed |
Grip | number, 0 to 1 | How far the grip is squeezed |
Thumbstick | Vector2 | Each axis from -1 to 1; never begins or ends |
A, B | 0 or 1 | Right hand: lower and upper face buttons |
X, Y | 0 or 1 | Left hand: lower and upper face buttons |
Menu | 0 or 1 | The menu button |
ThumbstickPress | 0 or 1 | Clicking 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
| Event | Arguments | Fires when |
|---|---|---|
SessionStarted | mode | An XR session begins |
SessionEnded | none | The session ends |
InputBegan | hand, name | A control is pressed, or a trigger or grip passes 0.5 |
InputEnded | hand, name | The control is released |
TrackingChanged | node, tracked | The head or a hand gains or loses tracking |
PlaneAdded | plane | The device detects a surface |
PlaneRemoved | plane | A 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
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:
| Field | Unit |
|---|---|
Latitude, Longitude | Degrees |
Altitude | Meters |
Heading | Degrees |
HorizontalAccuracy, VerticalAccuracy | Meters |
HeadingAccuracy | Degrees |
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:
| Key | Meaning |
|---|---|
origin_lat, origin_lon | Where the Space's origin is, in degrees |
origin_alt | Meters above the WGS84 ellipsoid; 0 if absent |
north_heading | Degrees 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
- Turn on the toolbar's XR Emulator toggle.
- Press Play.
- 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:
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:
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:
| Tool | What it does |
|---|---|
xr_state | Reads the session, the world poses of the head and hands in world meters, their controls, the settings and the emulator's held values |
xr_anchors | Lists the anchors and detected planes, with their tracking state and world poses |
xr_emulator | Turns the XR emulator on or off, the toolbar toggle; while on, Play runs an emulated session |
xr_set_pose | Holds the emulator's head or a controller at a world pose in meters; clear gives it back |
xr_input | Holds a fake control on a hand, such as a trigger squeeze or the A button; clear releases it |
xr_passthrough | Turns 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.