Gyroscope

Turns tilting and shaking your phone into a control for your Lens. Ask for a tilt game, for example a maze where you roll a ball to the exit.

Camera, Audio & Sensors

Camera feed, hand and face tracking, touch, tilt, haptics, and sound.

Made with this block

Inputs

shakeVelocityThresholdfloat

The velocity at which the shake gesture can be triggered.

shakeCooldownTimefloat

The time after a shake gesture is triggered before another can be triggered.

invertRotationboolean

Events

onShake

Activated when a user shakes their device. Do not use this for experiences where tilt controls position, as it can cause position to reset when a user doesn't intend it to.

Functions

resetRotationvoid

Calibrates the rotation 0 point to the user's current orientation, making rotation relative to it. Useful to call at the beginning of experiences to calibrate the rotation to make tilt relative to a comfortable starting rotation.

getRotationEulervec3

Returns rotation as a vec3 euler in degrees. rotationEuler.x is pitch, rotationEuler.z is yaw, rotationEuler.y is roll. The starting rotation is (0,0,0).

wrapEulervec3

Converts each angle of a euler rotation vector from 0-360 range to a wrapped euler value where 0->180 remains the same but 360 -> 180 becomes 0 -> -180. So tilting left on the roll axis may get a value of 10 and right -10. Useful for experiences where you don't need an absolute rotation like tilting the screen a certain amount. Example usage: const rotationEuler = script.gyro.getRotationEuler(); const wrappedRotation = script.gyro.wrapEuler(rotationEuler); Mapping: Roll = wrappedRotation.y → tilting right is negative, tilting left is positive -> POSITIVE SHOULD MOVE TO LEFT - NEGATIVE SHOULD MOVE TO RIGHT. Pitch = wrappedRotation.x → tilting up is positive, tilting down is negative -> POSITIVE SHOULD MOVE TO UP - NEGATIVE SHOULD MOVE DOWN. Yaw = wrappedRotation.z → rotating counterclockwise is positive, rotating clockwise is negative

to2DMotionvec2

Converts device tilt into a normalized 2D vector (X, Y) ranging from -1 to 1, where (-1, -1) is top-left and (1,1) is bottom right. It accepts a vec3 rotation and an optional threshold angle (default 15°) which determines how much tilt is required to reach the maximum velocity/value of 1. It's useful for converting rotation into linear motion. Use it like this: const rotEulers = script.gyro.getRotationEuler(); const motion2D = script.gyro.to2DMotion(rotEulers,6);