Scripting API
BodyTrackingModule Overview


The BodyTrackingModule class allows you to track the body and get Body details.


// Scales a rectangle to the bounding box of a detected body.
// Project setup:
// - Insert a rectangle to the scene

// Load in the required modules
const Diagnostics = require('Diagnostics');
const Scene = require('Scene');
const BodyTracking = require('BodyTracking');

(async function() { // Enable async/await in JS [part 1]

  // Locate the rectangle and canvas in the Scene
  const [rectangle, canvas] = await Promise.all([

  // Get the rectangle's transform
  const rectangleTransform = rectangle.transform;

  // Get the canvas width and height
  const canvasBounds = canvas.bounds;
  const canvasBoundsWidth = canvasBounds.width;
  const canvasBoundsHeight = canvasBounds.height;

  // Create a reference to a detected body
  const body = bodyTracking.body(0);
  // Get the center point of the body's bounding box 
  const bodyBoundingBox = body0.boundingBox;
  const bodyBoundingBoxCenter =;
  // Get whether the body is currently being tracked
  const tracked = body.isTracked;

  // Convert the normalized screen space value for x and y by multiplying by the
  // width and height of the canvas
  const scaledX = bodyBoundingBoxCenter.x.mul(canvasBoundsWidth);
  const scaledY = bodyBoundingBoxCenter.y.mul(canvasBoundsHeight);

  // Subtract the half the width/height to center the plane correctly and
  // multiply the y position by -1
  // This is required because 0,0 in the canvas is the bottom left of the device
  const rectangleX  = scaledX.sub(canvasBoundsWidth.div(2));
  const rectangleY = scaledY.sub(canvasBoundsHeight.div(2)).mul(1);

  // Bind the new values to the rectangle's x and y axis positions
  rectangleTransform.x = rectangleX;
  rectangleTransform.y = rectangleY;

  // Bind the new values to the rectangle's x and y axis scale
  rectangleTransform.scaleX = bodyBoundingBox.width;
  rectangleTransform.scaleY = bodyBoundingBox.height;

  // Add the values to the watch view"Count: ", bodyTracking.count);"Tracked: ", body.isTracked);"X position: ", bodyBoundingBox.x);"Y position: ", bodyBoundingBox.y);"Width: ", bodyBoundingBox.width);"Height: ", bodyBoundingBox.height);

})(); // Enable async/await in JS [part 2]


(get) count: ScalarSignal
(set) (Not Available)

Returns a ScalarSignal representing the count of tracked bodies.


body(index: number): Body

Returns a Body object.


BodyThe Body class exposes details of a tracked body.
Body2DArmRepresents a tracked arm in the body.
Body2DLegRepresents a tracked leg in the body.
Body2DPoseThe Body2DPose class exposes details of a tracked body's 2d key points.
Body2DTorsoRepresents a tracked torso in the body.
KeyPoint2DRepresents a single tracked 2d key point in the scene.