Accelerometer

Reference ❯ Detecting Device Motion and Gravity

Detecting Motion

Gravity top ↑

Syntax

Gravity
Gravity.x
Gravity.y
Gravity.z

This global variable represents the current direction and amount of gravity relative to the screen orientation while the viewer is running. The y component of this vector will almost always be negative, indicating that the device is being held upright.

x

float, the amount of gravity in the x direction

y

float, the amount of gravity in the y direction

z

float, the amount of gravity in the z direction

UserAcceleration top ↑

Syntax

UserAcceleration
UserAcceleration.x
UserAcceleration.y
UserAcceleration.z    

This global variable represents the current acceleration relative to the device while the viewer is running. You can use this to detect things such as shaking.

x

float, the amount of acceleration in the x direction

y

float, the amount of acceleration in the y direction

z

float, the amount of acceleration in the z direction

RotationRate top ↑

Syntax

RotationRate
RotationRate.x
RotationRate.y
RotationRate.z    

This global variable represents the rotation rate of the device around three axes. Internally, this makes use of the device gyroscope (if available). On devices where a gyroscope is not available, RotationRate is a zero vector.

x

float, the amount of rotation around the x axis

y

float, the amount of rotation around the y axis

z

float, the amount of rotation around the z axis