Skip to content

Handles

Updated

A Handle (comp-handle) makes its entity, with its children, something the player drags directly. There is no gizmo: the drag itself moves, turns or scales the entity, within the locks and limits you set for each axis. Use it for objects that move in a constrained way: a door on its hinge, a drawer on its rails, a knob, a slider, a lever, or a push button that does not move at all.

You should know:

  • Pointers, pointer types and the shared hover and leave events; see Selection and grabbing.
  • How events reach a script through a Signal Emitter; see Events and signals.
  • That an entity’s position and rotation are relative to its parent, and that rotations are in radians.
  1. Pressing any of the entity’s meshes, or a child entity’s, starts a drag. On desktop and mobile a screen pointer drags it; in XR a controller ray, a hand ray, a pinch or a fingertip poke all work. The cursor and hand props say which pointers it takes.
  2. One pointer carries it like a held object. Twisting an XR controller turns it too.
  3. The drag is filtered by the axis options: locked axes keep the value they had when the drag began, clamped axes stay within their range.
  4. With multitouch, a second pointer joins the drag: the midpoint between the two moves it, the line between them turns it, and their distance scales it.
  5. During a drag the pointer is captured and the camera controller stands down. A dynamic rigid body is led kinematically and gets its own type back on release. Anything else is moved through the entity’s transform.

Besides moving the entity, translate can turn the pointer’s motion into something else:

  • 'as-rotate' turns the pointer’s sweep around the entity’s origin into a rotation. To make a door, put the Handle on a group whose origin is at the hinge, with the door mesh as its child.
  • 'as-scale' scales the entity by the pointer’s distance from its origin.

translate, rotate and scale each take one of these values:

Value Meaning
true Every axis is free.
false Every axis is locked.
'x', 'y' or 'z' Only that axis moves.
{ x?, y?, z? } Per axis: true free, false locked, or [min, max] clamped to that range. A missing axis is free.
  • Ranges are absolute values in the parent’s frame, not amounts of change: z: [0, 0.4] means the entity’s local position.z stays between 0 and 0.4.
  • Ranges are in scene units for position, radians for rotation (a quarter turn is Math.PI / 2, about 1.5708), and factors for scale.
  • With uniformScale on, scale limits constrain the single shared factor; the tightest limit stops the resize.
Prop Type Default Description
translate axes, 'as-rotate' or 'as-scale' true Position axes the drag moves, or a drag mode.
rotate axes true Rotation axes the drag turns, in radians.
scale axes false Scale axes the drag stretches, as factors.
uniformScale boolean true Scale all axes by one factor.
multitouch boolean true A second pointer joins the drag: two hands rotate and scale.
cursor boolean true Dragged by a screen pointer or an XR controller ray.
hand boolean true Dragged by an XR hand close to it.

With both cursor and hand off, the entity is not hit by pointers at all.

Object Where the Handle goes translate rotate scale
Door opening a quarter turn A group whose origin is the hinge 'as-rotate' { x: false, y: [-1.5708, 0], z: false } false
Drawer sliding 40 cm The drawer { x: false, y: false, z: [0.03, 0.43] } false false
Knob turning about Y The knob 'as-rotate' 'y' false
Floor slider at a fixed height The slider { y: false } false false
Push button A group, with the cap as a child false false false
eventType EventType constant data When
Handle::start EventType.Handle.Start { pointerType } A drag began.
Handle::end EventType.Handle.End { pointerType } The drag ended: released, cancelled, or the component stopped listening.
Handle::hover EventType.Handle.Hover { pointerType } A pointer came over the entity.
Handle::leave EventType.Handle.Leave { pointerType } It left.

No event is sent on every frame during a drag. To follow the motion, read the entity’s transform in update while isDragging is true, or once on Handle::end.

With every axis locked (translate, rotate and scale all false), a Handle never moves. It still sends Handle::start on a press, even one with no drag, and Handle::end on release, from any pointer: a click, a tap, an XR ray, a pinch or a fingertip’s poke. That makes it a push button that works everywhere, including a real “press with your finger” in XR.

Member Description
isDragging true while the Handle is being dragged.
setProps(patch) Change locks and limits at runtime. A change ends any drag in progress first.
  • Which entities. Handle is offered on meshes, primitives, groups, text, media surfaces and UI panels.
  • Play only. In the editor, the editor’s transform gizmo takes over.
  • Object manipulation setting. When the project’s Allow Object Manipulation player setting is off, a Handle does not move, and a live drag is cancelled.
  • Multiplayer. Dragging the Handle of a networked entity asks for its ownership; see Multiplayer.
DoorSetup.jx
#pragma lifecycle(startup)
const OPEN = -Math.PI / 2; // a quarter turn
function startup() {
const hinge = findEntity('Door Hinge');
hinge.getComponent(HandleComponent).setProps({
translate: 'as-rotate',
rotate: { x: false, y: [OPEN, 0], z: false },
scale: false,
});
on('door', (event) => {
if (event.eventType !== EventType.Handle.End) return;
const openness = hinge.rotation.y / OPEN; // 0 closed, 1 fully open
log(`Door ${Math.round(openness * 100)}% open`);
if (openness > 0.9) emit('door/opened');
});
}
  • 'as-rotate' turns the player’s sweep around the group’s origin into a rotation, so the door swings about its hinge.
  • rotate locks X and Z and clamps Y between a quarter turn (-π/2) and closed (0). These are absolute angles in the parent’s frame.
  • On Handle::end, the script reads the hinge’s rotation.y to see how far the door is open, and announces when it is nearly fully open.
PushButton.jx
#pragma lifecycle(startup)
// The Button group has a Handle with translate, rotate and scale all false,
// and a Signal Emitter with the signal 'button'. Its child Cap is the part that moves.
function startup() {
const cap = findEntity('Cap');
const rest = cap.position.y;
on('button', (event) => {
if (event.eventType === EventType.Handle.Start) {
Tween.to(cap.position, { y: rest - 0.01 }, { duration: 0.05 });
}
if (event.eventType === EventType.Handle.End) {
Tween.to(cap.position, { y: rest }, { duration: 0.15 });
emit('lamp/toggle');
}
});
}
  • With every axis locked, the Handle never moves, but still reports press (start) and release (end).
  • The cap sinks a centimetre on press and springs back on release, using Tween.to to animate its position; see Animation.
  • The action fires on release, the way buttons usually behave, so a player can slide off to cancel.
DrawerState.jx
#pragma lifecycle(startup, update)
const CLOSED_Z = 0.03;
const OPEN_Z = 0.43;
let drawer;
let handle;
let wasOpen = false;
function startup() {
// The Drawer has a Handle: translate { x: false, y: false, z: [0.03, 0.43] }, rotate false.
drawer = findEntity('Drawer');
handle = drawer.getComponent(HandleComponent);
}
function update() {
if (!handle.isDragging) return;
const amount = (drawer.position.z - CLOSED_Z) / (OPEN_Z - CLOSED_Z); // 0 to 1
const open = amount > 0.5;
if (open !== wasOpen) {
wasOpen = open;
emit(open ? 'drawer/opened' : 'drawer/closed');
}
}
  • The Handle lets the drawer slide only along local Z, between the two limits.
  • Because no event arrives during the drag, the script reads position.z in update while isDragging is true.
  • wasOpen remembers the last state, so each signal is sent once when the drawer crosses the halfway point.
VolumeKnob.jx
#pragma lifecycle(startup)
const MIN_ANGLE = -2.4; // radians, turned fully clockwise (seen from above)
const MAX_ANGLE = 2.4; // turned fully counter-clockwise
function startup() {
// The Knob has a Handle and a Signal Emitter with the signal 'knob'.
const knob = findEntity('Knob');
knob.getComponent(HandleComponent).setProps({
translate: 'as-rotate',
rotate: { x: false, y: [MIN_ANGLE, MAX_ANGLE], z: false },
});
on('knob', (event) => {
if (event.eventType === EventType.Handle.Hover) Haptics.vibrate(10, { intensity: 0.2 });
if (event.eventType !== EventType.Handle.End) return;
// Turning clockwise lowers rotation.y: fully counter-clockwise is 0, fully clockwise is 1.
const volume = (MAX_ANGLE - knob.rotation.y) / (MAX_ANGLE - MIN_ANGLE);
emit('audio/volume', { value: Math.min(1, Math.max(0, volume)) });
});
}
  • The knob turns only about Y, within about 275 degrees, like a real volume knob.
  • A tiny buzz on hover tells an XR player their hand is on the knob; see Device and haptics.
  • On release, the angle is mapped to a volume between 0 and 1 and sent on a signal for an audio script to apply.
LockOnSolve.jx
#pragma lifecycle(startup)
function startup() {
const hinge = findEntity('Door Hinge');
const handle = hinge.getComponent(HandleComponent);
on('puzzle/solved', () => {
// Snap the door shut, then lock every axis.
hinge.setRotation(0, 0, 0);
handle.setProps({ translate: false, rotate: false, scale: false });
log('The door is locked');
});
on('puzzle/reset', () => {
handle.setProps({ translate: 'as-rotate', rotate: { x: false, y: [-Math.PI / 2, 0], z: false } });
});
}
  • A setProps call that locks every axis turns the door into an immovable object. If the player is dragging it, the drag ends first.
  • setRotation puts the door back to closed through the entity’s transform setter.
  • Restoring the original props unlocks it again.
  • Using deltas as limits. Limits are absolute values in the parent’s frame. A drawer whose rest position is z = 0.03 needs [0.03, 0.43], not [0, 0.4].
  • Degrees instead of radians. Rotation limits are in radians. Use Math.PI / 2 for 90°.
  • A door that spins around its middle. 'as-rotate' turns around the entity’s origin. Put the Handle on a group whose origin is on the hinge.
  • Waiting for a per-frame event. There is none. Read the transform in update while isDragging, or on Handle::end.
  • Expecting a Handle drag to snap into a Snap Zone. Snap zones react only to Grabbable drags.