- Home /
android accelerometer left right
I'm trying to create android app that makes use of the accelerometer, to do so I'm using this script: #pragma strict
function Update () { transform.Translate(Input.acceleration.x, 0, -Input.acceleration.z); }
in this way, the controlled object moves back and forth to the right and left, but I want to move only left and right. how can I fix it?
In the editor like in all 3D. X is left and right, Y is up and down, Z is forward and back. Think about which of the parameters also need to be 0 so it only moves left and right.
Answer by Quaker_SDR · Sep 01, 2014 at 11:46 AM
function Update () { transform.Translate(Input.acceleration.x, 0,0); }
will do
Answer by killerstreak · Sep 01, 2014 at 11:51 AM
x means horizontal z means depth and y means height. you include -input.acceleration.z in your code. get rid of it:
 function Update{
 transform.Translate(Input.acceleration.x,0,0);
 }
Answer by killerstreak · Sep 01, 2014 at 11:51 AM
Translate takes 3 values: horizontal=x vertical=y and depth=z
 transform.Translate(x, y, z)
you include -Input.acceleration.z wich is the source of the back and forth movement. get rid of it:
 function Update () { transform.Translate(Input.acceleration.x, 0, 0); }
Your answer
 
 
             Follow this Question
Related Questions
moving like a snake to the right and to the left 1 Answer
Android Accelerometer - Change Orientation 0 Answers
Using Accelerometer to move and rotate a 3d cube from left to right 0 Answers
How to set GUI X and Y positions from accelerometer.x and accelerometer.y ? 1 Answer
Help requested: Google VR / Phone rotation to gameobject. 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                