- Home /
 
How to calibrate my accelerometer? (available options not working)
So I'm making an android app, kind of similar to a flying game, and I wrote a code to use accelerometer if available (or if checked on) and if not make it use the touch controls. This all works fine, however I have to hold my tablet in a 180 degree angle to fly straight... After 2 days of googling all possible options on how to callibrate the accelerometer, I didn't come across one that works... So I decided to write my own by getting the accelerometer input at the start and then substract it from the new input. It kind of works now, but when I hold my tablet straight down, I'm not able to fly down by tilting my tablet towards me. Same goes for when I hold my tablet straight up when starting a level. Could anyone help me please? Here is the code I'm using:
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class Manager : MonoBehaviour
 {
     public static Manager Instance { get; set; }
 
     public Material playerMaterial;
     public Color[] playerColors = new Color[10];
     public GameObject[] playerTrails = new GameObject[10];
     public GameObject[] playerSkins = new GameObject[4];
 
     public int currentLevel = 0;    // Used when changing from menu to game scene
     public int menuFocus = 0;       // Used when entering menu scene, to know which menu to focus on
 
     private Dictionary<int, Vector2> activeTouches = new Dictionary<int, Vector2>();
     private Vector3 zeropoint;
 
     private void Awake()
     {
         DontDestroyOnLoad(gameObject);
         Instance = this;
     }
 
     public void Start()
     {
         zeropoint = Input.acceleration;
     }
 
     public Vector3 GetPlayerInput()
     {
         // Are we using accelerometer?
         if(SaveManager.Instance.state.usingAccelerometer)
         {
             
             // If we can, replace Y param by Z, we don't need y
             Vector3 a = Input.acceleration - zeropoint;
             a.y = a.z;
             return a;
         }
 
 // And then the touch control settings
 }
 
 
              Your answer