Skip to main content

MotionController

Class

Gives access to motion data and touch events from an external device to Spectacles, as well as haptic feedback requests from Spectacles to an external device.

  • Snapchat: not supported
  • SPECS: fully supported
  • Camera Kit Web: not supported
  • Camera Kit Mobile: not supported
  • SnapchatNot supported — SPECS only
  • SPECSFully supported
  • Camera Kit WebNot supported — SPECS only
  • Camera Kit MobileNot supported — SPECS only

Platform details

  • Snapchat — Not supported — SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — SPECS only.

  • Camera Kit Mobile — Not supported — SPECS only.

Gives access to motion data and touch events from an external device to Spectacles, as well as haptic feedback requests from Spectacles to an external device. Currently, the API supports Mobile Controller only, allowing one motion controller to be connected at a time. Developers use the Motion Controller API through the MotionControllerModule in Lens Studio.

Index

Example

const MotionControllerModule = require("LensStudio:MotionControllerModule")
let options = MotionController.Options.create()
const motionController = MotionControllerModule.getController(options);

const sceneObject = script.getSceneObject();
const transform = sceneObject.getTransform();

motionController.onTransformEvent.add((eventData) => {
transform.setWorldPosition(eventData.worldPosition)
transform.setWorldRotation(eventData.worldRotation)
})

Extends

Properties

onControllerStateChange

readonly onControllerStateChange: event1<boolean, void>

SPECS only

An event triggered when the selected controller's state changes between being available for use (connected, properly set up, and transmitting data) and otherwise.


onMotionTypeChange

readonly onMotionTypeChange: event1<MotionType, void>

SPECS only

Event triggered when the motion type of the controller changes.


onTouchEvent

readonly onTouchEvent: event4<vec2, number, number, TouchPhase, void>

SPECS only

Triggered by a touch event from the controller. Arguments:

  • normalizedPosition: A normalized 2D position of the user's touch on the touchpad. The coordinates range from ([0-1], [0-1]), where (0,0) represents the top-left and (1,1) represents the bottom-right.
  • touchId: Returns the unique identifier of the specific touch; useful for distinguishing between multiple simultaneous touches.
  • timestampMilliseconds: Returns the timestamp, in milliseconds, of when the touch event occurred.
  • phase: The current state of the touch.

onTouchpadSizeChange

readonly onTouchpadSizeChange: event2<vec2, vec2, void>

SPECS only

Triggered when the touchpad size is changed. Custom controllers can adjust the interactable area of the touchpad.


onTrackingQualityChange

readonly onTrackingQualityChange: event1<TrackingQuality, void>

SPECS only

Event triggered when the tracking quality state of the motion controller changes.


onTransformEvent

readonly onTransformEvent: event2<vec3, quat, void>

SPECS only

An event is triggered when new motion data becomes available. The arguments are the world position and the world rotation of the motion controller, respectively.


options

readonly options: MotionControllerOptions

SPECS only

Returns the configuration of the motion controller.

Methods

getMotionState()

getMotionState(): MotionType

SPECS only

Get the current motion type being provided by the motion controller.

Returns

MotionType


getTouchpadPhysicalSize()

getTouchpadPhysicalSize(): vec2

SPECS only

Returns the size of the touchpad in centimeters. Returns null if motion controller is not connected.

Returns

vec2


getTouchpadPointSize()

getTouchpadPointSize(): vec2

SPECS only

Returns the size of the touchpad in points. Returns null if motion controller is not connected.

Returns

vec2


getTrackingQuality()

getTrackingQuality(): TrackingQuality

SPECS only

Returns the tracking quality state of the motion controller, indicating whether the data received from it is accurate or not.

Returns

TrackingQuality


getTypeName()

static getTypeName(): TypeName<MotionController>

SPECS only

Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().

Returns

TypeName<MotionController>

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


getWorldPosition()

getWorldPosition(): vec3

SPECS only

Returns the last known position of the motion controller in world coordinate space. If no motion data has been received, or the motion type is set to 3DOF or NoMotion, this value will be null.

Returns

vec3


getWorldRotation()

getWorldRotation(): quat

SPECS only

Returns the last known rotation of the motion controller in world coordinate space. If no motion data has been received or the motion type is set to NoMotion, this value will be null.

Returns

quat


invokeHaptic()

invokeHaptic(hapticRequest): void

SPECS only

Invokes haptic feedback on the controller using a preset of options, if supported.

Parameters

ParameterType
hapticRequestHapticRequest

Returns

void


isControllerAvailable()

isControllerAvailable(): boolean

SPECS only

Indicates whether the selected controller is currently available to use. This means that the device is connected, properly set up, and transmitting data.

Returns

boolean


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object is the same as other. Useful for checking if two references point to the same thing.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame

See also

Motion Controller Module guide.

Nested types

Namespaces

NamespaceDescription
Options-

Enumerations

EnumerationDescription
HapticFeedbackDefines a set of haptic feedback patterns that can be requested.
MotionTypeEnum for describing the motion type.
TouchPhaseEnum that defines a current state of a touch interaction with the touchpad of the motion controller.
TrackingQualityDescribes Motion Controller tracking quality state, whether the data received from the Motion Controller is accurate or not.

Classes

ClassDescription
HapticRequestDescribes a request for haptic feedback.
MotionControllerOptionsSettings for configuring a motion controller.