Skip to content

The camera ​

The RTS camera looks at a point on the ground; the player scrolls, drags and zooms it. You set its limits in the view, move it from the view's code, and move one player's from the rules.

Quick start ​

ts
import type { GameView } from '@v12-engine/client'

const camera: NonNullable<GameView['world']>['camera'] = {
	pitch: 56, // degrees from the ground
	distance: 32,
	minDistance: 12, // 12 when left out
	maxDistance: 48, // 48 when left out
	zoomSpeed: 1,
	zoomToPointer: false,
	pitchCurve: (distance) => 40 + distance * 0.4, // closer is flatter, as in Warcraft III
	bounds: { minX: 20, minZ: 20, maxX: 200, maxZ: 200 }, // the whole map when left out
	yaw: 0,
	turn: true
}

Put it in GameView.world.camera.

Common tasks ​

Pan to a point ​

ts
client.camera.panTo({ x: 40, z: 60 }, 1.5, 'inOutCubic')
client.camera.lookAt({ x: 40, z: 60 }) // at once

Follow a unit ​

ts
client.follow(heroId, { smoothing: 0.3 }) // about 0.3 s behind
client.follow(null) // let go

Lock the camera to an area ​

ts
client.camera.lock({ minX: 20, minZ: 40, maxX: 60, maxZ: 80 })
client.camera.free()

A lock holds against the player, lookAt, panTo, a follow and saved views. To show the move, pan there first and lock once it arrives.

Change zoom limits while playing ​

ts
client.camera.setLimits({ min: 10, max: 60 })

The player's zoom setting is a share of this limit.

Move a player's camera from a mission ​

ts
import { cameraFor, cameraStep, defineSequence, wait } from '@v12-engine/engine'

cameraFor(world, 1, { shake: { strength: 0.5 } })

const ambush = defineSequence({
	id: 'ambush',
	steps: [
		cameraStep(1, { pan: { x: 40, z: 60, seconds: 2, ease: 'inOutCubic' } }),
		wait(2),
		cameraStep(1, { lock: { minX: 20, minZ: 40, maxX: 60, maxZ: 80 } }),
		wait(10),
		cameraStep(1, { lock: null })
	]
})

Only that player's screen moves. lock and bounds are kept in the world (a save has them); pan and shake are not.

Hear when the bounds change ​

ts
const stop = client.on('boundsChanged', ({ bounds, locked }) => minimap.outline(bounds, locked))

Or declared: GameView.on: { boundsChanged: (change, client) => … }.

Reference ​

client.camera ​

CallWhat it does
camera.lookAt(point)look at the point at once
camera.lookAt(point, { seconds, ease })the same, eased (panTo)
camera.panTo(point, seconds = 1, ease?)move over in seconds; ease a curve or a name of viewTimers.ease (inOutQuad)
camera.panning, camera.stopPan()whether a pan is under way; stop it where it is
camera.lock(bounds), camera.free(), camera.lockedkeep the view in an area; a zero-size area pins it to a point
camera.bounds = boundswhere the player may look from now on
camera.shake(x, z, strength)shake for something heavy, less the farther off; not if the player turned screenShake off
camera.setLimits({ min, max })zoom limits
client.follow(id, { offset, smoothing })keep the view on an entity; smoothing is about how many seconds behind

A pan gives way to the player scrolling, lookAt, or a cinematic. A pan ends a follow and a follow ends a pan. A cinematic ignores bounds and locks; the view comes back inside as it lets go.

cameraStep and cameraFor fields ​

FieldWhat
panpanTo, with an ease by name (the client's or GameView.cinematics.eases); 1 s by default
lockcamera.lock; null frees it
boundscamera.bounds; null goes back to the view's
shakecamera.shake, where the view looks when no x and z

The camera command ​

A screen can ask for the same with a command, which goes into the replay:

ts
session.send({ type: 'camera', pan: { x: 40, z: 60 } })

It speaks for the sending seat; one naming another seat is refused. The player's own scrolling is never in a replay.

For cinematic cameras (shots, rails, follows), see Cameras and shots.