Camera

Camera gives you full control over the camera in a World scene. Drop it as a child of World to replace the default camera and controls with your own configuration.

When World detects a <Camera> child, it automatically skips its built-in camera and orbit controls — no extra flags needed.

tsx
import { Camera } from "@carverjs/core/components";

Quick Start #

Perspective camera with orbit controls #

tsx
<World>
  <Camera type="perspective" controls="orbit" />
  <Actor type="primitive" shape="box" color="red" />
</World>

Orthographic camera (2D-style) #

tsx
<World mode="2d">
  <Camera type="orthographic" />
  <Actor type="sprite" src="/player.png" />
</World>

Follow a target #

tsx
const playerRef = useRef<Group>(null);

<World>
  <Camera
    type="perspective"
    follow={{
      target: playerRef,
      offset: [0, 5, 10],
      smoothing: 0.1,
    }}
  />
  <Actor ref={playerRef} type="model" src="/player.glb" />
</World>

Get the imperative API #

tsx
<Camera
  type="perspective"
  controls="orbit"
  onReady={(api) => {
    // api.shake(), api.moveTo(), api.lookAt()
  }}
/>

Props Reference #

PropTypeDefaultDescription
type"perspective" | "orthographic""perspective"Camera projection type
controls"orbit" | "map" | "pointerlock" | "none""none"Controls mode
followCameraFollowConfigFollow configuration. Omit for a static camera
perspectivePropsPerspectiveCameraPropsOverrides for the PerspectiveCamera (when type="perspective")
orthographicPropsOrthographicCameraPropsOverrides for the OrthographicCamera (when type="orthographic")
orbitControlsPropsOrbitControlsPropsOverrides for OrbitControls (when controls="orbit")
mapControlsPropsMapControlsPropsOverrides for MapControls (when controls="map")
pointerLockControlsPropsPointerLockControlsPropsOverrides for PointerLockControls (when controls="pointerlock")
onReady(api: UseCameraReturn) => voidCallback receiving the imperative camera API

Built-in Defaults #

PropertyPerspectiveOrthographic
Position[0, 5, 10][0, 0, 100]
FOV / Zoom7550
Near0.10.1
Far10001000

CameraFollowConfig #

FieldTypeDefaultDescription
targetRefObject<Object3D>Required. Ref to the Object3D to follow
offset[x, y, z][0, 5, 10]Position offset from the target
smoothingnumber0.1Lerp factor (0–1). Lower = smoother, higher = snappier
lookAtbooleantrueWhether the camera looks at the target
lookAtOffset[x, y, z][0, 0, 0]Offset for the look-at point

Controls #

ModeDescription
"none"No controls — camera is static or driven by follow / imperative API
"orbit"Click-drag to orbit around a point, scroll to zoom
"map"Pan and zoom controls suited for top-down views
"pointerlock"First-person style — locks the cursor and rotates on mouse move

Ref #

Camera forwards a ref to the underlying Three.js camera object:

tsx
const cameraRef = useRef<PerspectiveCamera>(null);
<Camera ref={cameraRef} type="perspective" />

Type Definitions #

See Types for CameraType, CameraControlsType, CameraFollowConfig, PerspectiveCameraProps, OrthographicCameraProps, MapControlsProps, PointerLockControlsProps, and UseCameraReturn.