Skip to content

scene.camera ​

Properties ​

gamepad read-only ​

  • Type: any
  • Which camera controls a game controller keeps where the experience drives its own camera: move is the left stick and the triggers, orbit the right stick and its click, which resets the view. Set one to false to use those inputs yourself; both return to true when the scene changes. While the camera follows or looks at something, move has no effect anyway.

kind read-only ​

  • Type: string
  • Who moves the camera: "orbit" where the experience drives its own camera (the Mac, the preview outside AR), "device" where the device is the camera (AR, Apple Vision Pro). Changes when the preview switches in or out of AR.

mode read-only ​

  • Type: string
  • "free", "follow" or "lookAt": what the last call set up.

Methods ​

follow() ​

javascript
scene.camera.follow(target: ObjectEntity | RepresentationEntity, options?: Object): boolean

Keep an object in view: the camera's orbit moves along with it, and dragging or the right stick still swings around it. Moving inputs (keys, two-finger pan, the left stick) stop moving the camera until release(). The right stick's click returns to the framing the follow started with. Ends when the scene changes or the object leaves the scene, which warns.

Example:

javascript
var ball = scene.findEntity({ name: 'Ball' });
scene.camera.follow(ball, { distance: 1.6, elevation: 30, offset: Vector3(0, 0.1, 0) });

Parameters:

  • target (ObjectEntity | RepresentationEntity) - The object to follow.
  • options (Object) (optional)
  • options.distance (number) (optional) - Metres from the camera to the target; default: as now.
  • options.azimuth (number) (optional) - Degrees around the target; 0 looks toward -z. Default: as now.
  • options.elevation (number) (optional) - Degrees above the horizon; default: as now.
  • options.offset (Vector3) (optional) - World-space metres from the object's origin to the point the camera aims at, such as above a character's feet. Default Vector3(0, 0, 0).
  • options.damping (number) (optional) - Seconds the camera takes to settle after the object moves; 0 is rigid. Default about 1.5.
  • options.verticalDamping (number) (optional) - The same for height, so a jump needn't bob the view. Default damping, or about 3.8 when damping is omitted.
  • options.elevationRange (Array<number>) (optional) - [min, max] degrees the player can orbit between. Default [0, 60].
  • options.orbit (boolean) (optional) - Whether dragging and the right stick orbit. Default true.
  • options.zoom (boolean | any) (optional) - Whether pinch and scroll change the distance, optionally within metres. Default true.

Returns: boolean

lookAt() ​

javascript
scene.camera.lookAt(target: ObjectEntity | RepresentationEntity, options?: Object): boolean

Turn the camera toward an object and keep it turned there while the object moves. The camera stays where it is, or moves to from; dragging and zooming do nothing until release(). The right stick's click does nothing meanwhile. Ends when the scene changes or the object leaves the scene, which warns.

Example:

javascript
scene.camera.lookAt(hero, { from: Vector3(3, 1.6, 4), damping: 0.8 });

Parameters:

  • target (ObjectEntity | RepresentationEntity) - The object to look at.
  • options (Object) (optional)
  • options.from (Vector3) (optional) - Where the camera stands, in world space. Default: where it is.
  • options.offset (Vector3) (optional) - World-space metres from the object's origin to the point the camera aims at. Default Vector3(0, 0, 0).
  • options.damping (number) (optional) - Seconds the aim takes to settle after the object moves; 0 is rigid. Default about 1.5.

Returns: boolean

release() ​

javascript
scene.camera.release(): void

Hand the camera back to the player, from where it is now.

Returns: void