Legacy Documentation: Version 5.1
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

Gyroscope.gravity

Switch to Manual
public var gravity: Vector3;

Description

Returns the gravity acceleration vector expressed in the device's reference frame.

	var movementScale: float;

function Update() { // A "spirit level" - the dot product of the gravity and the Y axis (ie, Vector3.up) // is a measure of how far the device is from level on that axis (it will be zero // if the device is perfectly level). This value can be used to position an object // to act as the "bubble". var pos = transform.position; pos.y = Vector3.Dot(Input.gyro.gravity, Vector3.up) * movementScale; transform.position = pos; }