I'm trying to rotate an object with the same tilt as my mobile
I found this thread that is really helpful
http://answers.unity3d.com/questions/139294/match-the-tilted-angle-of-phone-to-object.html
But, when I put the device in landscape orientation and try to tilt the mobile between left and right, the object rotate in Z and Y axis
I would like to lock Y axis when the mobile is in horizontal, but not when it's in vertical
I put an image about I'm trying:
EDIT:
private var sizeFilter: int = 15;
private var filter: Vector3[];
private var filterSum = Vector3.zero;
private var posFilter: int = 0;
private var qSamples: int = 0;
function MovAverage(sample: Vector3): Vector3 {
if (qSamples==0)
filter = new Vector3[sizeFilter];
filterSum += sample - filter[posFilter];
filter[posFilter++] = sample;
if (posFilter > qSamples)
qSamples = posFilter;
posFilter = posFilter % sizeFilter;
return filterSum / qSamples;
}
function Update() {
var temp: Vector3 = -MovAverage(Input.acceleration.normalized);
temp.x *= -1;
transform.up = temp.normalized;
}