Skip to main content

Virtual cameras

A Virtual Camera is a camera shot: where the camera should be and what it should look at. It draws nothing itself. The game is still seen through the main camera, and the virtual camera that is live moves it there. When another one goes live, the main camera blends over to it. This works like Unity's Cinemachine.

Use them for a follow camera, a camera that orbits a boss, a side-on 2D camera with a dead zone, a dolly shot along a track, and for cutting between them in gameplay and in Timelines.

Three virtual cameras on the same hero: a dolly along a curve, a follow camera, and an orbit around the statue
Three virtual cameras on the same hero: a dolly along a curve, a follow camera, and an orbit around the statue

Add one​

  1. Select the object to follow (your player).
  2. + Add → Virtual Camera. It follows the selected object straight away: Follow is set to it, Position Control is Follow and Rotation Control is Rotation Composer.
  3. Press ▶ Play. The main camera now goes where the virtual camera is.

Keep the scene's normal Camera object: it is the one the game is drawn through. Don't put a Camera component on a virtual camera's object.

Select a virtual camera to see its shot in the corner of the scene view
Select a virtual camera to see its shot in the corner of the scene view

In the editor, select a virtual camera to see its shot in the camera picture in the corner of the scene view. The picture shows where it would be with its targets where they are now, without damping or noise. A Timeline's camera track shows it there too.

Which one is live​

  • The enabled virtual camera with the highest Priority is live.
  • If two have the same Priority, the one switched on last wins.
  • Switch shots by changing priorities, or by switching virtual cameras on and off (Set enabled). When the live one is switched off, the next one takes over.
  • Make live camera switches it on and puts its Priority above every other one.
  • A Timeline Camera cuts clip that names a virtual camera makes it live for the clip, whatever the priorities. When the clip ends, the live one by priority blends back in, over the clip's Blend Out if it has one, otherwise with its own Blend In.

When no virtual camera is enabled, the main camera is left where it is and your own camera code (or Camera follow) moves it again.

Settings​

SettingWhat it does
PriorityHigher is live first.
FollowThe object Position Control follows (Cinemachine's Tracking Target).
Look AtThe object Rotation Control aims at. Empty aims at the Follow object.
Field of ViewThe lens, for a perspective main camera. It blends too, so a shot can zoom in.
Orthographic SizeHalf the height of the view, for an orthographic (2D) main camera.
Noise → AmplitudeA handheld wobble, in degrees. 0 is steady. Frequency sets how fast it wobbles.
Blend In → StyleHow the view moves over when this one goes live: Cut, Ease In Out, Ease In, Ease Out or Linear.
Blend In → TimeSeconds the blend takes.
Confiner → Bounding VolumeAn object the camera stays inside (see Confiner).
card virtual camera

Position Control​

ModeWhere the camera goes
NoneWhere the virtual camera's object is. Move it yourself, or with a Timeline or a script.
FollowFollow Offset away from the Follow object. Binding Mode: World Space keeps the offset in world directions, Lock to Target With World Up turns it with the object, so the camera stays behind a car as it turns.
Orbital FollowOn a sphere of Radius around the Follow object. Horizontal Axis and Vertical Axis are the starting angles (0 is behind, on +Z). With Input on, the player turns it with the mouse, the right stick or a drag; Vertical Min and Max stop it going under the ground or over the top.
Position ComposerKeeps its own rotation and slides so the Follow object sits on its screen spot, Camera Distance away. The 2D side-on camera: with a dead zone the hero can move a little before the camera follows.
Spline DollyRides along a Curve object (Spline). With Automatic Dolly it stays at the point of the curve nearest the Follow object. Without it, Position sets where (0 is the start, 1 the end). Offset moves it off the curve.
Hard Lock to TargetExactly on the Follow object: a first-person view.

Damping is how many seconds the camera takes to catch up, per axis (X, Y, Z): 0 is at once, 1 lags softly. In Follow mode the axes turn with the binding, so Z is "behind".

Rotation Control​

ModeWhere the camera looks
NoneThe way the virtual camera's object faces.
Rotation ComposerTurns to keep the Look At object on its screen spot. With a dead zone it only turns when the object leaves the zone.
Hard Look AtAlways straight at the Look At object.
Rotate With Follow TargetThe same rotation as the Follow object: a view from a cockpit or a turret.

Target Offset moves the point aimed at, for example up to the head (Y 1.5). Damping is the seconds to catch up.

Screen spot and dead zone​

Rotation Composer and Position Composer keep the target on a spot on the screen:

  • Screen X / Screen Y move the spot from the centre: −0.5 is the left (or bottom) edge, 0.5 the right (or top). Put a runner at X −0.2 so there is more room ahead of them.
  • Dead Zone Width / Height make a box around the spot, as a share of the screen (0 to 1). While the target is in the box the camera doesn't move. When it leaves, the camera moves just enough to bring it back to the edge of the box.

Confiner​

The Confiner keeps the camera inside an area, like Cinemachine's Confiner. A 2D camera stops at the edges of the level instead of showing what is past them.

  1. Add an object that covers the area the camera may show, for example a Cube scaled to the size of the level. Untick its Visible so it isn't drawn, and remove its Collider so nothing bumps into it.
  2. On the virtual camera, set Confiner → Bounding Volume to that object.
SettingWhat it does
Bounding VolumeThe object whose bounds the camera stays inside: its mesh, or for an empty object a box as big as its Scale.
Confine Screen EdgesOn (the default): the whole view stays inside, so the edge of the screen stops at the edge of the box. For a perspective camera, it is the view at the distance of what it looks at. Off: only the camera's position stays inside (a 3D room the camera must not leave).

If the view is bigger than the box, the camera stays in the middle of the box.

Shakes​

  • Noise on a virtual camera is a steady handheld wobble that lasts as long as the shot.
  • Shake camera (Camera actions) shakes the screen for a moment.
  • Camera impulse shakes it from an object: full strength there, weaker the farther the camera is, nothing past Radius. An explosion far away barely moves the view. A weaker shake never cuts a stronger one short.

Events and scripts​

Camera actions and conditions: Make live camera, Set camera priority, Set camera targets (empty keeps what it has), Is live camera, Camera impulse.

In scripts:

game.find('BossCam').makeLiveCamera(); // live now, blending in
game.find('BossCam').isLiveCamera; // true while live
game.liveCamera(); // the live virtual camera, or null
const cam = game.find('FollowCam').component('virtualCamera');
cam.priority = 20;
cam.follow = game.find('Car').id; // follow another object
cam.offset = [0, 6, 12]; // every setting changes live
cam.confiner = game.find('Level2Bounds').id; // another area for the next room
game.shakeCamera(0.6, 0.4, bomb.position, 25); // an impulse from the bomb, 25 m radius

Things to know​

  • The main camera is moved after everything else in the frame, so it follows objects moved by physics, behaviors and scripts in the same frame.
  • A Timeline Camera cuts clip with a normal camera object (not a virtual one) wins over the virtual cameras while it lasts.
  • Blending moves the position, the turn and the lens together. A blend that is interrupted by another switch starts again from where the view is.
  • Several virtual cameras cost almost nothing: each one is a few sums a frame.