effect-motion
Learn

Camera

The 2.5D model — flat shapes in depth, driven by an AE-style camera

Every entity has a position with a z. Flat shapes placed at different depths are just layers — until the camera moves, and parallax and perspective scale turn them into a 2.5D set. This is the After Effects camera model, in code.

The default camera

Every scene has one, at rest: positioned back along +z so that at z: 0 one scene unit is one pixel, with a 50mm-equivalent focal length. You never have to touch it — every scene so far in this path used it unknowingly.

Get a handle with Scene.camera, or instantiate your own and make it active:

const camera = yield* Scene.instantiate("Camera", {});
yield* Scene.setCamera(camera);

Moving it

The camera is an entity — Motion.moveTo works on it directly. On top of that, Camera ships helpers for the moves that are about the view:

  • Camera.lookAt(point, duration?) — set (or ease into) a point of interest. From then on the aim is pinned: however the camera's position moves, the target stays framed. No orientation math in the scene.
  • Camera.dolly/dollyTo(distance, duration, easing?) — move along the view axis, toward/away from the point of interest. Not a z-tween (those only coincide while the camera is unrotated).
  • Camera.orbit/orbitTo(angle, duration, easing?) — swing around the point of interest at constant distance; the turntable move.
  • Camera.follow(instance, options?) — track a moving instance.

lookAt and follow name their target in the verb, so they have no base/To pair; dolly and orbit animate a value and keep the full pair, like any animator.

HUD: opting out of the camera

A Hud entity's subtree is projected through the identity camera — it stays bolted to the glass while the world moves behind it. Titles, lower-thirds, and annotations go there. A scene mounted with Scene.play has its own camera and its own HUD; see Precomps, masks and HUD.

0:00
import * as Camera from "effect-motion/Camera";import * as Color from "effect-motion/Color";import * as Entity from "effect-motion/Entity";import * as Motion from "effect-motion/Motion";import * as Scene from "effect-motion/Scene";// Flat shapes at different depths become a 2.5D set the moment the camera// moves: lookAt pins the aim to the subject, dollyTo pushes along the view// axis, and orbitTo swings around the point of interest — parallax does// the rest.export const scene = Scene.make(	"camera tour",	function* () {		// three depth planes of slabs around a glowing subject		const planes: ReadonlyArray<{ z: number; hex: string; y: number }> = [			{ z: 500, hex: "#3b3a5a", y: -160 },			{ z: 0, hex: "#544f80", y: -60 },			{ z: -700, hex: "#3d4266", y: 40 },		];		for (const plane of planes) {			for (let x = -900; x <= 900; x += 360) {				yield* Scene.instantiate("Rect", {					position: Entity.vec3({ x, y: plane.y, z: plane.z }),					width: 140,					height: 420,					fillColor: Color.hex(plane.hex),				});			}		}		yield* Scene.instantiate("Circle", {			position: Entity.vec3({ y: -40, z: -250 }),			radius: 90,			fillColor: Color.hex("#ff8906"),		});		// the scene's default camera, ready to be driven		const camera = yield* Scene.camera;		// aim at the subject; the point of interest pins the framing from here on		yield* camera.pipe(Camera.lookAt({ x: 0, y: -40, z: -250 }));		// push in along the VIEW axis (not a z tween), swing around, pull out		yield* camera.pipe(			Camera.dollyTo(2100, "2 seconds", "easeInOutCubic"),			Camera.orbitTo(0.6, "2 seconds", "easeInOutSine"),			Camera.orbitTo(-0.6, "2 seconds", "easeInOutSine"),		);		yield* Motion.wait("400 millis");	},	{		compositing: "depth",		width: 1920,		height: 1080,		backgroundColor: Color.rgba(22, 22, 29),	},);

Next: Randomness.

On this page