Skip to content

Camera controllers

Updated

A camera controller is a component that moves or turns its camera entity from player input, so you get mouse look, a third-person orbit or a model viewer without writing any input code. MIRA has four input controllers (First Person, Third Person, Orbit and Fly) and the Motion Path controller, which moves an entity along a curve for fly-throughs and moving platforms. Two helpers complete them: Camera Collision keeps an orbiting camera out of walls, and Cursor controls the mouse pointer and pointer lock.

  • Play only, and only while rendering. A controller acts in play, and only while its camera is the one rendering. Cut to another camera and it pauses; cut back and it resumes.
  • One input controller per camera. Adding or enabling First Person, Third Person, Orbit or Fly turns the other input controllers on that camera off. The latest one enabled wins; disabling it does not turn another back on.
  • Paused in XR. In an immersive session the headset owns the view, so controllers stand down.
  • Gestures start on the canvas. A Screen Gamepad’s sticks, UI that holds the pointer and page overlays never turn the camera.
Controller Type Use it for
First Person comp-first-person-controller The camera is the player’s eyes.
Third Person comp-third-person-controller Orbit behind a character.
Orbit comp-orbit-controller Turn around a point or an object, like a model viewer.
Fly comp-fly-controller Free flight through the scene.
Motion Path comp-motion-path-controller Fly-throughs along a curve; also moving props and platforms.
Controller Mouse and keys Touch Gamepad
First Person Left-drag looks; with a Cursor lock, the locked mouse looks without a button One finger looks Right stick looks
Third Person Left-drag orbits; the wheel zooms One finger orbits; a pinch zooms Right stick orbits; triggers zoom (left out, right in)
Orbit Left-drag orbits; the wheel zooms; with a point target, WASD or arrows pan and E/Q move it up and down One finger orbits; a pinch zooms; with a point target, two fingers pan Right stick orbits; triggers zoom; with a point target, the left stick pans
Fly Left-drag or pointer lock looks; WASD or arrows move, E/Q up and down One finger looks None

Sticks are analog: a light push turns or pans more slowly. A finger on the 3D view never scrolls or zooms the web page around it.

Third Person and Orbit follow a target. It can be:

  • an entity’s id or name, looked up in the camera’s scene;
  • from a script, the object itself: an entity, or any scene object such as a bone;
  • a world point [x, y, z], which the camera orbits in place.

You can change the target at any time with setProps({ target }). First Person and Fly have no target.

The camera is the player’s eyes. It turns in place; it never moves. Add a Character Controller to the same camera to walk.

Prop Type Default Description
lookHeight number 0 Raises the view above the camera entity, in world units. Negative lowers it.
lookSpeed number 0.15 Degrees per pixel of drag. 0 disables looking.
pitch number 0 Starting vertical angle above the horizon, in degrees.
pitchLimit number 85 Largest angle above or below the horizon, in degrees.
smoothTime number 0.08 Look settle time, in seconds. 0 is instant.

The camera orbits its target at distance, looking lookHeight above the target’s origin. Zoom stays within distance ± distanceRange, never nearer than 0.1. It never moves its target: put a Character Controller on the target to walk it.

Prop Type Default Description
target string, object or [x, y, z] '' What it follows. See Targets.
distance number 5 Starting distance from the target, in world units. Setting it jumps the zoom there.
distanceRange number 3 How far zoom goes in or out from distance. 0 turns zoom off.
lookHeight number 1.2 Height above the target’s origin it looks at, in world units.
lookSpeed number 0.25 Degrees per pixel of drag.
pitch number 15 Starting vertical orbit angle above the horizon, in degrees.
pitchLimit number 85 Largest angle above or below the horizon, in degrees.
smoothTime number 0.15 Follow settle time, in seconds. Higher is smoother but laggier.

Turns around a target, like a product viewer. With an entity target it follows the entity as it moves; with a point target the player can pan the point. The orbit starts at distance from the target, at the viewing angle given by where you placed the camera.

Prop Type Default Description
target string, object or [x, y, z] [0, 0, 0] What it orbits. See Targets.
distance number 8 Starting distance from the target, in world units.
distanceRange number 10 How far zoom goes from distance. 0 locks zoom.
rotateSpeed number 0.3 Degrees per pixel of drag.
moveSpeed number 5 Pan speed of a point target, world units per second.
pitchLimit number 89 Largest angle above or below the horizon, in degrees.
smoothTime number 0.1 Settle time, in seconds. 0 is instant.

A drag that starts in the scene keeps orbiting even if it crosses a UI panel; the wheel scrolls the UI it is over, and zooms over the scene.

Free flight, like a spectator camera. Looking works by left-drag, one finger or pointer lock; WASD or the arrows move along the view, and E and Q move up and down.

Prop Type Default Description
moveSpeed number 5 World units per second.
lookSpeed number 0.15 Degrees per pixel of drag.
pitchLimit number 89 Largest angle above or below the horizon, in degrees.
smoothTime number 0.08 Look settle time, in seconds. 0 is instant.

Moves its entity along a curve at constant speed: a cinematic fly-through, a moving platform, a patrolling prop. It is offered on cameras and on every entity that can carry an Animation Timeline. It writes the transform directly, so put a kinematic rigid body on an entity that must push things; a dynamic body is not moved with it. In XR, a camera on a path holds still while the headset leads the view.

Prop Type Default Description
pathType 'catmull-rom' or 'bezier' 'catmull-rom' catmull-rom passes through every point. bezier reads cubic segments: a start point, then control, control and end for each segment (1 + 3n points).
points array [] World-space points, each [x, y, z] or { x, y, z }. Catmull-Rom needs at least two points.
closed boolean false Close the loop. Catmull-Rom only.
tension number 0.5 Catmull-Rom tension.
duration number 8 Seconds to travel the whole path.
repeat 'once', 'repeat' or 'pingpong' 'repeat' At the end: stop, wrap to the start, or turn back.
orient 'tangent', 'target' or 'none' 'tangent' Face the direction of travel, look at lookTarget, or keep the current rotation.
lookTarget [x, y, z] or { x, y, z } [0, 0, 0] The point looked at with orient: 'target'.
autoStart boolean true Start moving when the entity activates.

Point values are copied when you set them: changing a THREE.Vector3 afterwards does nothing until the next setProps.

Method What it does
play() Start from where it is. A finished repeat: 'once' path starts again from the beginning.
pause() Freeze where it is.
resume() Carry on after pause(). A finished repeat: 'once' path stays at its end.
stop() Stop and rewind to the start.
setProgress(t) Jump to t, from 0 (start) to 1 (end).

With a Signal Emitter on the entity, a repeat: 'once' path sends MotionPathController::end (no data) when it reaches its last point. The Camera director page shows a full cutscene.

Camera Collision (comp-camera-collision) keeps a Third Person or Orbit camera out of walls and the ground, and its target in view. After the controller places the camera, it sweeps a small sphere from the look point to the camera; on a hit the camera pulls in just short of it, and eases back out once the way is clear.

  • Only fixed, non-sensor colliders stop it. Dynamic and kinematic bodies and sensors do not, so passing props never jerk the camera.
  • The followed object and its children are ignored.
  • It is on the physics layer collisionLayer; layers that do not collide with it (glass, foliage) let it through.
Prop Type Default Description
radius number 0.2 Sweep radius in world units.
recoverTime number 0.3 How quickly it eases back out, in seconds.
collisionLayer integer 0 The physics layer the camera is on, 0 to 15.

It costs one sweep per frame while its camera renders, and runs in play only, not in XR.

Cursor (comp-cursor) controls the mouse pointer over the canvas while its camera entity is active in play. It can replace the system cursor with an image, and lock the pointer for mouselook.

Prop Type Default Description
src string '' Image URL for the cursor, up to 128×128 pixels. Empty keeps the system cursor.
hotspot [x, y] [0, 0] The click point in the image, in pixels.
lock boolean false Lock the pointer on a left click on the canvas, so the mouse looks around without holding a button.

When the component deactivates, the system cursor comes back and the pointer lock is released. Browsers without pointer lock simply skip it; touch and drag input keep working.

1. Switch between first and third person with V

Section titled “1. Switch between first and third person with V”
ViewToggle.jx
#pragma lifecycle(startup, update)
let firstPerson;
let thirdPerson;
function startup() {
// The player camera carries both controllers; Third Person targets the 'Hero' entity.
firstPerson = self.parent.getComponent(FirstPersonControllerComponent);
thirdPerson = self.parent.getComponent(ThirdPersonControllerComponent);
}
function update() {
if (!Input.keyboard.isKeyReleased(Key.V)) return;
if (firstPerson.enabled) thirdPerson.setEnabled(true);
else firstPerson.setEnabled(true);
}

Only one input controller can be enabled on a camera, and enabling one turns the others off. So toggling is just “enable the one that is not active”: the runtime disables the other for you. isKeyReleased fires once per press.

2. Point a third-person camera at whoever is selected

Section titled “2. Point a third-person camera at whoever is selected”
SpectateSelected.jx
#pragma lifecycle(startup)
const RACERS = ['Red Car', 'Blue Car', 'Green Car'];
function startup() {
const follow = findEntity('Spectator Cam').getComponent(ThirdPersonControllerComponent);
on('racers', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
const car = findEntity(event.entityId);
if (car && RACERS.includes(car.name)) {
follow.setProps({ target: car, distance: 7 });
}
});
}

When the player clicks a car, its Selectable sends Selectable::select through the car’s Signal Emitter, with the car’s id in event.entityId. The script passes the entity itself as the new target, and sets distance, which jumps the zoom to 7 units. See Selection and grabbing for Selectable.

3. A lift on a Motion Path, called by a button

Section titled “3. A lift on a Motion Path, called by a button”
LiftCall.jx
#pragma lifecycle(startup)
function startup() {
// The Lift has a kinematic Rigid Body and a Motion Path:
// two points (bottom, top), repeat: 'once', autoStart: false.
const lift = findEntity('Lift').getComponent(MotionPathControllerComponent);
let atTop = false;
on('lift/call', () => {
atTop = !atTop;
if (atTop) {
lift.setProps({ points: [[0, 0, 0], [0, 6, 0]] });
} else {
lift.setProps({ points: [[0, 6, 0], [0, 0, 0]] });
}
lift.setProgress(0);
lift.play();
});
}

The Motion Path moves the lift at constant speed over duration. Each call swaps the direction by reversing the two points, rewinds to the start with setProgress(0) and plays. Because the lift has a kinematic rigid body, it carries whatever stands on it instead of passing through.

1. A model viewer that recentres on a part

Section titled “1. A model viewer that recentres on a part”
ViewerFocus.jx
#pragma lifecycle(startup)
const HOME = [0, 1, 0];
function startup() {
const orbit = findEntity('Viewer Cam').getComponent(OrbitControllerComponent);
const point = new THREE.Vector3();
on('viewer/focus', (data) => {
const part = findEntity(data.part);
if (!part) return;
part.getWorldPosition(point);
orbit.setProps({ target: [point.x, point.y, point.z], distance: 2, distanceRange: 1.5 });
});
on('viewer/home', () => orbit.setProps({ target: HOME, distance: 8, distanceRange: 10 }));
}

A UI button emits viewer/focus with a part name. The script reads the part’s world position and gives Orbit a point target there, so the player can still pan around it with WASD or two fingers. It also tightens the zoom range for close inspection. viewer/home restores the wide view.

2. Lock the mouse for aiming, release it for menus

Section titled “2. Lock the mouse for aiming, release it for menus”
AimLock.jx
#pragma lifecycle(startup)
function startup() {
// The player camera has a First Person controller and a Cursor.
const cursor = self.parent.getComponent(CursorComponent);
on('menu/open', () => cursor.setProps({ lock: false, src: '' }));
on('menu/close', () => cursor.setProps({ lock: true }));
}

With lock: true, the next left click on the canvas captures the pointer and the mouse looks around without holding a button. When a menu opens, the script turns the lock off and restores the system cursor so the player can click buttons.

  • Expecting First Person to walk. Controllers only look. Add a Character Controller to the same camera.
  • Two controllers enabled at once. It cannot happen: enabling one disables the others. If your camera “stops working”, check which controller was enabled last.
  • Moving a dynamic body with Motion Path. It writes the transform, which a dynamic body ignores. Use a kinematic rigid body.
  • Changing a THREE.Vector3 passed in points. Points are copied on setProps. Call setProps again with the new values.
  • Camera Collision that does nothing. It needs an enabled Third Person or Orbit controller, and only fixed colliders on a colliding layer stop it.
  • A controller that ignores input during a cutscene. It only acts while its camera renders. Cut back with CameraDirector.switchToMain().