0

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:

enter image description here

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;
}
rubengc
  • 1
  • 2
  • Maybe you can use [Input.deviceOrientation](http://docs.unity3d.com/Documentation/ScriptReference/Input-deviceOrientation.html) – Verv Apr 15 '14 at 02:02
  • Your images are a bit confusing. Do you change the camera when you lay the phone parallel to the ground as in 2nd and 3rd images? It would be nice to see some code and a video on how it acts. However, you won't be able to do this by setting transform.up. You'll have to separate the components of Input.acceleration.normalized. – Gazihan Alankus Apr 15 '14 at 13:39
  • I edit the first post with the code, you only need attach this script to a gameObject to see the problem, i thinking probably i will need separe the rotation, but I don't know how to, because is easy separe Y and X axis, but, how will I to combine them for diagonal rotations? – rubengc Apr 16 '14 at 12:39

0 Answers0