Skip to main content

Cameras

A camera decides what your visitor sees and how they move around. Set its control mode, its lens, and extra views such as minimaps.

Control modes​

ModeThe visitor…
nonecannot move the camera; you move it yourself
orbitdrags to rotate around a target, and scrolls to zoom
flyflies freely with the keys and the mouse
firstPersonlooks around from where they stand, with the pointer captured
lockhas the pointer captured, while the camera keeps following its object
Use lock for a character

firstPerson detaches the camera from its object. That is fine for someone walking around a model. It does not work for a character, because the camera stops following the body.

lock captures the pointer too, but keeps the camera attached. The mouse movement goes to your script instead. Use it for a first-person game.

Orbit settings​

orbit is the default mode, because it suits product viewers. It has the most settings:

SettingWhat it does
targetthe point the camera orbits around
enableRotate · enablePan · enableZoomwhich gestures are allowed
minDistance · maxDistancehow close and how far the visitor can get
minPolarAngle · maxPolarAnglehow far they can swing above and below
enableDamping · dampingFactorhow long the motion glides after they let go
autoRotate · autoRotateSpeeda slow automatic spin

Limit the polar angle on almost every product viewer. Otherwise visitors can swing under the floor and see the scene from below, and that never looks right, whatever the lighting.

Lens​

  • fov is the field of view in degrees. 50 looks natural. Lower values look zoomed in and flatter. Higher values show more and look more dramatic.
  • near and far set the range that gets drawn. Anything closer than near or further than far is cut off.
Flickering surfaces

When far is huge compared to near, surfaces that are close together start to flicker. This is called z-fighting. To fix it, raise near first. It helps much more than lowering far.

Fly settings​

In fly mode the visitor moves with keys. You can change the keys, or use one of the project's named key bindings instead. Speed and a boost multiplier set how fast the camera moves. By default, the boost is on while Shift is held.

Extra views​

An extra view draws a second picture from a camera, on top of the main one. Use it for a minimap, a rear-view mirror or a security monitor.

Add it to an object that already has a camera, then choose where it draws:

  • screen: a rectangle on the screen. You set its position and size as fractions of the screen.
  • texture: an image that a material can show.

With texture, you can build a working monitor. Draw a camera's view into a texture and put that texture on a screen object in your scene. The screen then shows another part of your world.

Extra views are drawn after the main picture, in the order you list them.

Each extra view draws the whole scene again

With two monitors, the scene is drawn three times. Use extra views where they matter, and turn them off where they do not.

Switch cameras from a script​

A scene is drawn through one camera at a time. A script can check which camera is active and switch to another:

ctx.camera.entity();
ctx.camera.setActive(securityCam);
ctx.camera.pose();

The camera's transform always decides where the camera is. Write to it to move the camera. In orbit and firstPerson modes, the controls set the rotation, so a rotation you write is overwritten. The position you write is kept. See the ctx API.

If game controls drive a camera, that camera's own control mode is ignored. Otherwise the two would conflict on every frame.


Next: Prefabs — reuse groups of objects and draw thousands of copies.