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.
Key concepts
Section titled “Key concepts”- 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
CameraDirectorglobal. It decides which camera renders right now and lets a script cut to another camera (a cutscene, a security monitor) withCameraDirector.switchTo(name)and back withCameraDirector.switchToMain();CameraDirector.currentis 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.
How it works
Section titled “How it works”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.
Your first camera script
Section titled “Your first camera script”This walkthrough adds a security camera the player can switch to with the C key.
-
Add a Perspective Camera entity, name it
Security Cam, and aim it at the room. Your scene keeps its main camera for the player. -
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();} -
Enter play and press C to cut to the security camera, and C again to come back.
isKeyReleasedis true for one frame per press, so each press switches once.switchTocuts to a camera by name;switchToMain()returns to the player’s view.
Your first camera script: press C to cut from the main camera to a security camera with CameraDirector.switchTo, and C again to come back.
Click the view, then press C to switch cameras, and C again to switch back.
Choosing
Section titled “Choosing”| 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 | Camera |
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 |
Entity types
Section titled “Entity types”The two kinds of camera are entity types, each with a page of its components, props, events and a first script:
| Entity | Type | What it is |
|---|---|---|
| Camera Orthographic | ent-camera-orthographic | No perspective, for top-down, isometric and 2D views. |
| Camera Perspective | ent-camera-perspective | Normal 3D camera: far things look smaller. |
In scripts
Section titled “In scripts”| Global | What it is |
|---|---|
CameraDirector | Cut between cameras by name or id: switchTo(name), switchToMain(); current and main are the camera entities. |
camera | The camera the player sees through |
PerspectiveCameraComponent | A perspective camera: things further away look smaller, as the eye sees them. See CameraComponent for placement, activation and the editor gizmo. |
OrthographicCameraComponent | An 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. |
MainCameraComponent | Marks its camera as its scene's main camera: the player's view. |
FirstPersonControllerComponent | First-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. |
ThirdPersonControllerComponent | Third-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. |
OrbitControllerComponent | OrbitControls-style camera on a CameraEntity. It orbits its OrbitControllerProps.target: a world point, or an entity it follows as it moves. |
FlyControllerComponent | Free-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. |
MotionPathControllerComponent | Animates 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. |
CameraCollisionComponent | Keeps 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. |
CursorComponent | Governs 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). |
CameraRecoilEffectComponent | The 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. |
CameraImpactEffectComponent | A 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. |
FollowTargetComponent | Follows an explicit target in play, with a movement deadzone and transient manual rebase. |
Components
Section titled “Components”| Component | Type | What it does |
|---|---|---|
| Camera Breathing | comp-camera-breathing | Gentle idle sway, like a handheld camera. |
| Camera Collision | comp-camera-collision | Keeps a following camera out of walls and the ground. |
| Camera Dizzy | comp-camera-dizzy | A woozy, off-balance drift, set off by a script. |
| Camera Head Bob | comp-camera-head-bob | Step bounce while the camera walks. |
| Camera Impact | comp-camera-impact | A push from one side, like a hit, set off by a script. |
| Camera Orthographic | comp-camera-orthographic | No perspective, for top-down, isometric and 2D views. |
| Camera Perspective | comp-camera-perspective | Normal 3D camera: far things look smaller. |
| Camera Recoil | comp-camera-recoil | The kick of the player's own shot or swing, set off by a script. |
| Camera Tremor | comp-camera-tremor | Shaking from a quake or an explosion, set off by a script. |
| Cursor | comp-cursor | Custom mouse cursor image and pointer lock for mouselook. |
| First Person Controller | comp-first-person-controller | Mouse-look from the player's eyes. |
| Fly Controller | comp-fly-controller | Free-fly camera: look with the mouse, move with WASD and E/Q. |
| Follow Target | comp-follow-target | Follows an entity ID or name with a movement deadzone. |
| Main Camera | comp-main-camera | Makes this camera its scene's player view. One per scene; a second one waits and takes over when the first goes. |
| Motion Path Controller | comp-motion-path-controller | Moves the entity along a spline: a fly-through, a platform, a patrol. |
| Orbit Controller | comp-orbit-controller | Drag to orbit, wheel to zoom around a point or entity. |
| Third Person Controller | comp-third-person-controller | Camera orbiting behind a target character. |
In this section
Section titled “In this section”| Topic | Description |
|---|---|
| Cameras | Perspective and orthographic cameras, their projection props, the main camera and taking pictures with capture(). |
| Camera director | Cutting between cameras with Camera, 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. |