I’m trying to get a ship to rotate left or right on the screen, based on whether the player is tilting the phone left or right. I can get it to acknowledge the tilt, and it seems like the rotation change works, but it also wants to rotate along the other axis. I can’t figure out why. As far as I can tell, I’m not changing them in any way. I’ve tried it on both the Z and Y axis and they both seem to work the same.
I’m using Unity 3.0 for Android, by the way.
void FixedUpdate () {
Vector3 rotationAccel = new Vector3(0,0,0);
//forward or reverse thrust based on tilt
dir.z = Input.acceleration.x;
if (dir.sqrMagnitude > 1) dir.Normalize();
rigidbody.AddForce(dir * forceStrength);
//rotation left or right based on tilt
rotationAccel.z = Input.acceleration.y;
if (rotationAccel.z > 0)
{
changeRot = rigidbody.rotation.z + (rotSpeed * Time.deltaTime);
rigidbody.rotation = new Quaternion(rigidbody.rotation.x, rigidbody.rotation.y, changeRot, rigidbody.rotation.w);
}
else if (rotationAccel.z < 0)
{
changeRot = rigidbody.rotation.z - (rotSpeed * Time.deltaTime);
rigidbody.rotation = new Quaternion(rigidbody.rotation.x, rigidbody.rotation.y, changeRot, rigidbody.rotation.w);
}
}
Any help?