Page 1 of 1

accelerometer control for android

PostPosted: Mon Apr 15, 2013 5:36 pm
by ayushpal
hi ! im new here
can anyone tell me that how to make accelerometer control in a game for android device ?
for example : if i want to run my character in left direction using accelerometer , so what should i type in the script ?

Re: accelerometer control for android

PostPosted: Mon Apr 15, 2013 8:53 pm
by skydereign
You can use the getAccelerometer function as described on this page. http://game-editor.com/docs/script_reference.htm
For your game though, you won't be using key events, but rather checks in the player's draw actor.
player -> Draw Actor -> Script Editor
Code: Select all
Vector v = getAccelerometer();
if(v.x>0.2) // moving right
{
    x+=5;
}
else if(v.x<-0.2)
{
    x-=5;
}

You'll need to figure out which axis are which, as this might need to use v.y instead of v.x depending on the orientation of the phone.