Skip to content

Instantly share code, notes, and snippets.

@mattshapiro
Created February 18, 2016 01:04
Show Gist options
  • Save mattshapiro/5e812ad45ca561253996 to your computer and use it in GitHub Desktop.
Save mattshapiro/5e812ad45ca561253996 to your computer and use it in GitHub Desktop.
Unity 5 Accelerometer-based game object rotation
float x = -Input.acceleration.x * 180;
float y = Input.acceleration.y * 180;
x = limit (x, MAX_ANGLE);
y = limit (y, MAX_ANGLE);
Quaternion quato = Quaternion.Euler(y, 0, x);
rb.transform.rotation = Quaternion.Lerp(rb.transform.rotation, quato, Time.deltaTime * 5.0f);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment