MotionController
ClassGives 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
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
Properties
Methods
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
readonlyonControllerStateChange: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
readonlyonMotionTypeChange:event1<MotionType,void>
SPECS only
Event triggered when the motion type of the controller changes.
onTouchEvent
readonlyonTouchEvent: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
SPECS only
Triggered when the touchpad size is changed. Custom controllers can adjust the interactable area of the touchpad.
onTrackingQualityChange
readonlyonTrackingQualityChange:event1<TrackingQuality,void>
SPECS only
Event triggered when the tracking quality state of the motion controller changes.
onTransformEvent
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
readonlyoptions: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
getTouchpadPhysicalSize()
getTouchpadPhysicalSize():
vec2
SPECS only
Returns the size of the touchpad in centimeters. Returns null if motion controller is not connected.
Returns
getTouchpadPointSize()
getTouchpadPointSize():
vec2
SPECS only
Returns the size of the touchpad in points. Returns null if motion controller is not connected.
Returns
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
getTypeName()
staticgetTypeName():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
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
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
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
invokeHaptic()
invokeHaptic(
hapticRequest):void
SPECS only
Invokes haptic feedback on the controller using a preset of options, if supported.
Parameters
| Parameter | Type |
|---|---|
hapticRequest | HapticRequest |
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
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
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
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
See also
Motion Controller Module guide.
Nested types
Namespaces
| Namespace | Description |
|---|---|
| Options | - |
Enumerations
| Enumeration | Description |
|---|---|
| HapticFeedback | Defines a set of haptic feedback patterns that can be requested. |
| MotionType | Enum for describing the motion type. |
| TouchPhase | Enum that defines a current state of a touch interaction with the touchpad of the motion controller. |
| TrackingQuality | Describes Motion Controller tracking quality state, whether the data received from the Motion Controller is accurate or not. |
Classes
| Class | Description |
|---|---|
| HapticRequest | Describes a request for haptic feedback. |
| MotionControllerOptions | Settings for configuring a motion controller. |