Re-Setting Acceleretor

Hello developers, i am working on sensor game but there’s a problem. I don’t know what can i do.

    // Move object using accelerometer
    var speed = 1.0;
    
    var totalZ : float;
       
    function Update () {
    
    Debug.Log(Input.acceleration.z.ToString());
    
    var dir : Vector3 = Vector3.zero;
     
    // we assume that device is held parallel to the ground
    // and Home button is in the right hand
     
    // remap device acceleration axis to game coordinates:
    // 1) XY plane of the device is mapped onto XZ plane
    // 2) rotated 90 degrees around Y axis
    
    //This equalizes to 0
    var zAxis = Input.acceleration.z + 0.75;
    var xAxis = Input.acceleration.x;
    
    dir.z = xAxis ;
    dir.y = zAxis;
     

    if (dir.sqrMagnitude > 1)
    dir.Normalize();
     
    dir *= Time.deltaTime;
     
    // Haraket Olasılıklarının Hepsi;
    
    if (Input.acceleration.z < -0.75){
    
    	totalZ = Mathf.Abs(Input.acceleration.z)* 2;
    	
		Debug.Log("Move Up");
		
		transform.Translate(-Vector3.up * totalZ * speed * Time.deltaTime);
    }
    
    if (Input.acceleration.z > -0.75){
    
    	totalZ = zAxis;
    	
    	Debug.Log("Move Down");
    	
    	transform.Translate(Vector3.up * totalZ * speed * Time.deltaTime);
    
    }
    
    
    
    
    }

this is my code. At there I’ve fixed acceretor to -0.75 as you see. Now i want to move up it’s ok but when i do “Down move starts at 0.25” but “Up move starts at 0.000001” i want to make “up” move start at 0.0001 but i can’t so help me please.

How about editing your [old question][1] instead of posting a new one? You should close or delete one of them. [1]: http://answers.unity3d.com/questions/581793/accelerometer-calibration.html

Deleted. So ? Will you help me ?

1 Answer

1

Well, the accelerometer gives you a vector. A lot of people only use single components of this vector an often get in trouble when they tilt the device in more than one axis.

The accelerometer just measures, well, lateral acceleration. In space it would return 0,0,0 if you don’t move your device. Rotating the device wouldn’t make any change since a rotation doesn’t accelerate the device in any axis.

So why does it work on earth? Well, we have something we call gravity :wink: It’s a constant acceleration towards the earth. That’s why you actually get a result from the meter, even when you don’t move.

The accelerometer detects the acceleration in 3 axis which are cf course constant to the device.
See this picture (powered be aldonaletto):
orientation

The gravity vector can be imagined like a pendulum with length 1.0, hanging down from your device. If it lies flat on the table it would be (0, 0, -1). If it stands up-right it would be (0, -1, 0). If you turn it 90° clockwise it would return (1, 0, 0).

One way to get something like a starting position at 45°, you could rotate the whole vector 45° around the x axis.

To rotate the vector you can simple use a quaternion like this:

    var acc = Input.acceleration * Quaternion.Euler(-45,0,0);

if you multiply your acceleration vector with this, the vector will be (0, -1, 0) when holding at 45°