Skip to content

Cameras

Updated

A camera decides what the player sees. In MIRA a camera is an ordinary entity: its projection component describes the lens, and its transform places and aims it, so you frame a shot by moving and rotating the entity. The camera director picks which camera renders and lets scripts cut to another one; camera controllers turn mouse, touch and gamepad input into camera motion; camera effects shake or sway the view; and Follow Target keeps a panel or prop near the player. To move the player’s body, see Movement; to change the look of the image, see Post-processing.

  • Camera entity: A Perspective Camera or Orthographic Camera entity. Its projection component holds the lens settings (field of view or view size, clip planes); its transform places and aims it. A camera cannot change projection: to switch between the two, place one of each and cut between them. Both kinds take the same optional components: an input controller, a Motion Path, Camera Collision, camera effects and post-processing effects. Any camera can take a picture with capture(), on screen or not.
  • Main camera: The camera marked with a Main Camera component. It is the player’s view in its scene, and a scene has one: it renders by default, and spawn points, spot points and teleports move it.
  • Camera director: The CameraDirector global. It decides which camera renders right now and lets a script cut to another camera (a cutscene, a security monitor) with CameraDirector.switchTo(name) and back with CameraDirector.switchToMain(); CameraDirector.current is the camera entity rendering now.
  • Camera controller: A component that moves or turns its camera from player input: First Person, Third Person, Orbit and Fly. One input controller is active per camera. Motion Path moves an entity along a curve instead.
  • Camera effect: A component that shakes or sways the view on top of the controller: breathing, head bob, recoil, tremor, impact, dizziness. Effects, like post-processing effects, belong to their camera, so cutting to another camera also changes the look.

Each frame, the camera director picks the rendering camera: the camera a script cut to, otherwise the main camera, otherwise the first camera in the scene. A controller acts only while its camera is the one rendering, so a cutscene camera never fights the player’s camera.

Cameras look; they never move a character. A controller only ever moves or turns its own camera entity, and camera effects add motion on top of it. In an immersive VR or AR session the headset owns the view: controllers and camera effects pause. See XR.

All of this acts in play only: cameras render only in play. The editor keeps its own camera for the viewport, and each placed camera shows its frustum.

This walkthrough adds a security camera the player can switch to with the C key.

  1. Add a Perspective Camera entity, name it Security Cam, and aim it at the room. Your scene keeps its main camera for the player.

  2. Add a Behavior entity anywhere in the scene with this script:

    SecurityCam.jx
    #pragma lifecycle(update)
    let watching = false;
    function update() {
    if (!Input.keyboard.isKeyReleased(Key.C)) return;
    watching = !watching;
    if (watching) CameraDirector.switchTo('Security Cam');
    else CameraDirector.switchToMain();
    }
  3. Enter play and press C to cut to the security camera, and C again to come back.

  • isKeyReleased is true for one frame per press, so each press switches once.
  • switchTo cuts to a camera by name; switchToMain() returns to the player’s view.
If you want… Use… Read
A view with depth, where far things look smaller: first person, third person, cutscenes Camera Perspective Cameras
A view without perspective: top-down maps, isometric views, 2D-style games Camera Orthographic Cameras
A camera with a lens, a clip range or an orthographic map view Perspective or Orthographic Camera Cameras
To cut to a cutscene or security camera and back CameraDirector Camera director
Mouse look, third-person orbit, a model viewer or free flight First Person, Third Person, Orbit, Fly Camera controllers
A scripted fly-through or a moving platform on a curve Motion Path Camera controllers
Shake, recoil, sway or a woozy view Camera effects Camera effects
A panel or prop that trails the player at a comfortable distance Follow Target Follow target
Sepia, pixel, bloom or other image effects Post-processing Post-processing

The two kinds of camera are entity types, each with a page of its components, props, events and a first script:

EntityTypeWhat it is
Camera Orthographicent-camera-orthographicNo perspective, for top-down, isometric and 2D views.
Camera Perspectiveent-camera-perspectiveNormal 3D camera: far things look smaller.
GlobalWhat it is
CameraDirectorCut between cameras by name or id: switchTo(name), switchToMain(); current and main are the camera entities.
cameraThe camera the player sees through
PerspectiveCameraComponentA perspective camera: things further away look smaller, as the eye sees them. See CameraComponent for placement, activation and the editor gizmo.
OrthographicCameraComponentAn orthographic camera: no perspective — things keep their size however far away they are, and parallel lines stay parallel. For top-down maps, isometric and 2D-style views, and blueprints. size sets how much of the world it shows. See CameraComponent for placement, activation and the editor gizmo.
MainCameraComponentMarks its camera as its scene's main camera: the player's view.
FirstPersonControllerComponentFirst-person look on a CameraEntity: the camera is the player's eyes, turned in place — yaw and clamped pitch, critically-damped by FirstPersonControllerProps.smoothTime — by a left-button drag, a finger dragged on a touch screen, or a gamepad's right stick (add CursorComponent with lock for buttonless mouselook). lookHeight raises or lowers the view above the entity without moving the body. It never moves the camera: add a CharacterControllerComponent to the same camera entity to walk, run and jump; spawn points and teleport place it.
ThirdPersonControllerComponentThird-person control on a CameraEntity: orbits at a fixed distance around the active ThirdPersonControllerProps.target, its follow and orbit both critically-damped (smoothDamp), looking lookHeight above it. A left-drag, a finger or a gamepad's right stick orbits (yaw + clamped pitch); the wheel, a two-finger pinch or the gamepad's triggers zoom within distance ± distanceRange, eased by the same spring. It never moves the target: a CharacterControllerComponent on it walks it. Acts only while its CameraComponent is the active render camera. Play-mode only.
OrbitControllerComponentOrbitControls-style camera on a CameraEntity. It orbits its OrbitControllerProps.target: a world point, or an entity it follows as it moves.
FlyControllerComponentFree-fly camera control on a CameraEntity, the editor's fly style in play: left-drag, a finger dragged on a touch screen, or a held pointer lock looks, WASD/arrows move along the look direction, E/Q raise/lower. It owns its own transform (it follows no target) and acts only while its CameraComponent is the active render camera. Play-mode only.
MotionPathControllerComponentAnimates its entity along a spline — Catmull-Rom through the points, or composed cubic Bézier segments — at constant arc-length speed, orienting along the tangent or at a fixed target: a camera's cinematic fly-through, a moving platform, a patrolling prop. Offered wherever an Animation Timeline is. A camera on a path holds in XR, the headset leading the view. It writes the transform directly: a dynamic rigid body on the entity is not moved with it. Play-mode only.
CameraCollisionComponentKeeps a following camera out of walls and the ground, and its target in view: a spring-arm collision test. After the camera's Third Person or Orbit controller has placed it (onLateUpdate), a bounded sphere is swept from the controller's look point to the camera through the physics world. On a hit the camera is pulled in to just short of it, within a few frames (PULL_TIME); once clear it eases back out over recoverTime.
CursorComponentGoverns the pointer over the renderer canvas on a CameraEntity: swaps the OS cursor for a custom image (CursorProps.src) and/or captures it via Pointer Lock for classic first-person mouselook (CursorProps.lock).
CameraRecoilEffectComponentThe kick of the player's own action — a shot, a swing, a throw: the view pitches up by rotationAmplitude and moves back by amplitude, then returns over duration. Always the same kick, never random and never oscillating; for shaking from outside use the Tremor effect, for a hit the Impact effect. Visual only: where the player aims does not change.
CameraImpactEffectComponentA blow from one side — a punch, a projectile: the view is pushed the way the blow travels, bounces once and settles within duration. Pushed back it tilts up; pushed sideways it rolls away. For shaking from no direction use the Tremor effect, for the player's own shot the Recoil effect.
FollowTargetComponentFollows an explicit target in play, with a movement deadzone and transient manual rebase.
ComponentTypeWhat it does
Camera Breathingcomp-camera-breathingGentle idle sway, like a handheld camera.
Camera Collisioncomp-camera-collisionKeeps a following camera out of walls and the ground.
Camera Dizzycomp-camera-dizzyA woozy, off-balance drift, set off by a script.
Camera Head Bobcomp-camera-head-bobStep bounce while the camera walks.
Camera Impactcomp-camera-impactA push from one side, like a hit, set off by a script.
Camera Orthographiccomp-camera-orthographicNo perspective, for top-down, isometric and 2D views.
Camera Perspectivecomp-camera-perspectiveNormal 3D camera: far things look smaller.
Camera Recoilcomp-camera-recoilThe kick of the player's own shot or swing, set off by a script.
Camera Tremorcomp-camera-tremorShaking from a quake or an explosion, set off by a script.
Cursorcomp-cursorCustom mouse cursor image and pointer lock for mouselook.
First Person Controllercomp-first-person-controllerMouse-look from the player's eyes.
Fly Controllercomp-fly-controllerFree-fly camera: look with the mouse, move with WASD and E/Q.
Follow Targetcomp-follow-targetFollows an entity ID or name with a movement deadzone.
Main Cameracomp-main-cameraMakes this camera its scene's player view. One per scene; a second one waits and takes over when the first goes.
Motion Path Controllercomp-motion-path-controllerMoves the entity along a spline: a fly-through, a platform, a patrol.
Orbit Controllercomp-orbit-controllerDrag to orbit, wheel to zoom around a point or entity.
Third Person Controllercomp-third-person-controllerCamera orbiting behind a target character.
Topic Description
Cameras Perspective and orthographic cameras, their projection props, the main camera and taking pictures with capture().
Camera director Cutting between cameras with CameraDirector, cutscenes, and the Camera::relocate hand-over.
Camera controllers First Person, Third Person, Orbit, Fly and Motion Path, plus Camera Collision and Cursor.
Camera effects Breathing, head bob, recoil, tremor, impact and dizzy effects, and how to trigger them.
Follow target Keep an entity placed relative to a moving target, with tolerances and smoothing.