A Motion Controller allows to communicate 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 Asset.MotionControllerModule in Lens Studio.

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)
})
interface MotionController {
    onControllerStateChange: event1<boolean, void>;
    onMotionTypeChange: event1<MotionType, void>;
    onTouchEvent: event4<vec2, number, number, TouchPhase, void>;
    onTouchpadSizeChange: event2<vec2, vec2, void>;
    onTrackingQualityChange: event1<TrackingQuality, void>;
    onTransformEvent: event2<vec3, quat, void>;
    options: MotionControllerOptions;
    getMotionState(): MotionType;
    getTouchpadPhysicalSize(): vec2;
    getTouchpadPointSize(): vec2;
    getTrackingQuality(): TrackingQuality;
    getTypeName(): string;
    getWorldPosition(): vec3;
    getWorldRotation(): quat;
    invokeHaptic(hapticRequest: HapticRequest): void;
    isControllerAvailable(): boolean;
    isOfType(type: string): boolean;
    isSame(other: ScriptObject): boolean;
}

Hierarchy (view full)

Properties

onControllerStateChange: event1<boolean, void>

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: event1<MotionType, void>

Event triggered when the motion type of the controller changes.

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

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: event2<vec2, vec2, void>

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

onTrackingQualityChange: event1<TrackingQuality, void>

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

onTransformEvent: event2<vec3, quat, void>

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.

Returns the configuration of the motion controller.

Methods

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

    Returns MotionType

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

    Returns vec2

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

    Returns vec2

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

    Returns TrackingQuality

  • 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

  • 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

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

    Parameters

    Returns void

  • 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

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

    Parameters

    • type: string

    Returns boolean

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

    Parameters

    Returns boolean