- Home /
Question by
danhanly · Aug 08, 2012 at 03:47 PM ·
rotationjavascriptipadaccelerometer
Realtime Object Rotation on iPad
I have an box, and I would like to reflect real gravity on the box.
There are numerous items contained in the box and I would like to rotate my iPad to affect the rotation of the box.
I cant get this to work quite right.
Here's the script I'm using (JS):
function Update () {
rotation=-Input.acceleration.y;
var rotationVector:Vector3 = new Vector3(0, 0,rotation);
// Move object
root.transform.Rotate(rotationVector);
}
root
is the gameObject of my box.
The rotation on this seems to be quite erratic, I can't get it to work quite right. Basically, if my iPad is Portrait (It's a landscape-right app), I want the box to rotate to 90 degrees; this means it's be -90 the other way and 180 if viewing in landscape-left. I know I can detect orientation directly, but I want to detect for all values in between and not just fixed values.
Can anybody help?
Comment