Camera Orthographic
Updated
No perspective, for top-down, isometric and 2D views.
- Type
ent-camera-orthographic- Script class
OrthographicCameraEntity- Family
- Cameras
Overview
Section titled “Overview”A Camera Orthographic entity is a camera without perspective: things keep their size at any distance, and parallel lines stay parallel. Use it for top-down maps, isometric views, 2D-style games and blueprint-like views.
Its lens is its required Camera Orthographic component (comp-camera-orthographic), and its transform places and aims it. The projection component cannot be removed or switched off; to turn a camera off, switch off its entity.
Cameras render only in play. In the editor the viewport has its own camera, and each placed camera shows its frustum and an icon you click to select it. The Main Camera component marks the scene’s player view, and scripts cut to other cameras with CameraDirector.
For a view with depth, where far things look smaller, use a Camera Perspective. A common pattern is a perspective main camera for play and an orthographic camera for a map the player switches to.
The props:
sizeis the height of the view, in world units,10by default and at least0.001. Its width follows the viewport’s aspect ratio. An orthographic camera zooms by changingsize: smaller is closer.nearandfarare the clip planes,0.1and2000by default. Anything outside them is not drawn.
When the viewport is resized during play, the camera keeps its size and adjusts its width to the new aspect ratio.
Set it up
Section titled “Set it up”- Add a Camera Orthographic entity to the scene (see Scenes and hierarchy).
- Place it above or beside the area to show and rotate it to look at it: straight down for a map, tilted for an isometric view.
- Set
sizeto the height of the area the view should cover. - Decide which camera is the player’s view: keep the Main Camera on the camera the player starts with, and cut to the others with
CameraDirector.
Examples
Section titled “Examples”Zoom a map with the mouse wheel
Section titled “Zoom a map with the mouse wheel”Goal: zoom an orthographic map in and out with the wheel, within limits.
The script is on the Camera Orthographic, which looks straight down.
#pragma lifecycle(startup, update)
const MIN_SIZE = 5;const MAX_SIZE = 60;
let map;let size;
function startup() { map = self.parent.getComponent(OrthographicCameraComponent); size = map.props.size;}
function update() { const wheel = Input.mouse.wheelDelta(); if (wheel === 0) return; size = Math.min(MAX_SIZE, Math.max(MIN_SIZE, size * (1 - wheel * 0.001))); map.setProps({ size });}self.parent.getComponent(OrthographicCameraComponent)returns the camera’s lens component, andmap.props.sizethe authored view height.Input.mouse.wheelDelta()is the wheel movement this frame; scrolling up is positive and makes the view smaller, which zooms in.sizeis clamped betweenMIN_SIZEandMAX_SIZE, andsetPropsruns only on frames where the wheel turned.
Toggle a top-down map view
Section titled “Toggle a top-down map view”Goal: pressing M cuts to the map camera; pressing it again returns to the player’s view.
Map Cam is a Camera Orthographic without a Main Camera, looking straight down at the level.
#pragma lifecycle(update)
let onMap = false;
function update() { if (!Input.keyboard.isKeyReleased(Key.M)) return; onMap = !onMap; if (onMap) CameraDirector.switchTo('Map Cam'); else CameraDirector.switchToMain();}isKeyReleased(Key.M)is true for exactly one frame per press, so one press is one toggle.CameraDirector.switchTo('Map Cam')cuts to the camera by name;switchToMain()cuts back to the main camera.- While the view is cut away, the main camera’s controllers pause, and they resume when it comes back.
A map camera that follows the player
Section titled “A map camera that follows the player”Goal: keep the map centred on the player while the map view is shown, and widen it when the player runs.
#pragma lifecycle(startup, update)
const HEIGHT = 40;let mapCam;let lens;let player;const position = new THREE.Vector3();const last = new THREE.Vector3();
function startup() { mapCam = findEntity('Map Cam'); lens = mapCam.getComponent(OrthographicCameraComponent); player = CameraDirector.main; player?.getWorldPosition(last);}
function update(dt) { if (!player || dt === 0 || CameraDirector.current !== mapCam) return;
player.getWorldPosition(position); mapCam.setPosition(position.x, position.y + HEIGHT, position.z);
const speed = position.distanceTo(last) / dt; last.copy(position); const goal = speed > 4 ? 30 : 15; const size = lens.props.size + (goal - lens.props.size) * Math.min(1, dt * 2); if (Math.abs(size - lens.props.size) > 0.01) lens.setProps({ size });}CameraDirector.mainis the main camera entity, here the player’s view. The map camera follows it only while it is the camera rendering (CameraDirector.current).setPosition(x, y, z)keeps the map cameraHEIGHTmetres above the player. Its rotation, looking straight down, never changes.- The speed is the distance moved since the last frame divided by the frame time. The vectors are created once and reused.
sizeeases toward 15 m when walking and 30 m when running, andsetPropsis skipped when the change is tiny.
- Keep
nearandfararound the area the camera shows: a huge range reduces depth precision. - A scene has one main camera. Leave the Main Camera off map and overview cameras, and cut to them with
CameraDirector. CameraDirector.switchTothrows when no camera has that name; keep names in your scripts in sync with the scene.
Components
Section titled “Components”What a new Camera Orthographic is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Camera Orthographic | comp- |
Required | One | No perspective, for top-down, isometric and 2D views. |
You can also add 37 optional components, such as Animation Graph, Animation Timeline, Ascii Effect, Bloom Effect, Camera Breathing, Camera Collision.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
| Prop | Default | Range |
|---|---|---|
size |
10 |
0. |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
It reports the events every entity has: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
An Orthographic Camera looks straight down on a little town, with no perspective: the mouse wheel changes its size, the height of the view, the arrow keys move it across the map, and a click selects a house, shown with an animated outline.
Turn the mouse wheel over the map to zoom between 5 and 60 m of view height. Click a house to select it, then hold the arrow keys to move across the map.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Camera Orthographic.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Camera Orthographic'); if (!(entity instanceof OrthographicCameraEntity)) return;
// Its Camera Orthographic component holds the settings listed under Props. const component = entity.getComponent(OrthographicCameraComponent); log('size is', component.props.size); component.setProps({ size: 15 });}