Skip to content

Camera Orthographic

Updated

No perspective, for top-down, isometric and 2D views.

Type
ent-camera-orthographic
Script class
OrthographicCameraEntity
Family
Cameras

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:

  • size is the height of the view, in world units, 10 by default and at least 0.001. Its width follows the viewport’s aspect ratio. An orthographic camera zooms by changing size: smaller is closer.
  • near and far are the clip planes, 0.1 and 2000 by 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.

  1. Add a Camera Orthographic entity to the scene (see Scenes and hierarchy).
  2. 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.
  3. Set size to the height of the area the view should cover.
  4. 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.

Goal: zoom an orthographic map in and out with the wheel, within limits.

The script is on the Camera Orthographic, which looks straight down.

MapZoom.jx
#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, and map.props.size the authored view height.
  • Input.mouse.wheelDelta() is the wheel movement this frame; scrolling up is positive and makes the view smaller, which zooms in.
  • size is clamped between MIN_SIZE and MAX_SIZE, and setProps runs only on frames where the wheel turned.

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.

MapToggle.jx
#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.

Goal: keep the map centred on the player while the map view is shown, and widen it when the player runs.

MapFollow.jx
#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.main is 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 camera HEIGHT metres 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.
  • size eases toward 15 m when walking and 30 m when running, and setProps is skipped when the change is tiny.
  • Keep near and far around 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.switchTo throws when no camera has that name; keep names in your scripts in sync with the scene.

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-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Camera Orthographic comp-camera-orthographic 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.001 ≤ x ≤ 100000

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.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

OrthographicCameraEntity.jx
#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 });
}