Search Unity

Gyro Y axis problem help Y axis/angle is wrong

Discussion in 'Scripting' started by siberhecy, Jul 26, 2017.

  1. siberhecy

    siberhecy

    Joined:
    Aug 1, 2016
    Posts:
    21
    Hello everyone i need help in gyro..
    Firstly im using mobile device Portrait mode..
    1
    Debug.Log(gyro.attitude.y);

    This code gives me Y axis/angle but its wrong.
    When i turn my phone to up down or left right Y is changing..
    It must be only change Y when i turn my phone left right..
    Why up down is affect Y angle ?
     
  2. Cookieg82

    Cookieg82

    Joined:
    Mar 28, 2017
    Posts:
    73
    Code (CSharp):
    1. using System;
    2. using UnityEngine;
    3.  
    4. public class Gyro : MonoBehaviour
    5. {
    6.     public float moveSpeed = 80f;
    7.  
    8.     private Rigidbody rb;
    9.  
    10.     // Use this for initialization
    11.     void Start()
    12.     {
    13.         rb = gameObject.GetComponent<Rigidbody>();
    14.     }
    15.  
    16.     public void Update()
    17.     {
    18.         Vector3 movement = new Vector3(Input.acceleration.x, 0f, Input.acceleration.y);
    19.         rb.AddForce(movement * moveSpeed);
    20.     }
    21. }
    This is what I use for Gyro. It works, not perfect but it works (Landscape mode). You may be able to use this for portrait?
     
  3. siberhecy

    siberhecy

    Joined:
    Aug 1, 2016
    Posts:
    21
    Sorry but its not gyro ... its acceleration :D
    This is the gyro link ; https://docs.unity3d.com/ScriptReference/Gyroscope.html
    Thanks for reply btw :)