Change gravity with accelerometer?

How can i change gravity with a phones accelerometer? I have a ball inside a myWorld movieclip, and i want to move the ball around the stage using the accelerometer which controls the gravity, and so far i can get it to kind of work with something like this...

Code: Select all

var Accelerometer_3:Accelerometer = new Accelerometer();
Accelerometer_3.addEventListener(AccelerometerEvent.UPDATE, AccelerometerUpdate);

function AccelerometerUpdate(event:AccelerometerEvent):void
{
   myWorld.gravityX-= event.accelerationX*9.8;
   myWorld.gravityY += event.accelerationY*9.8;
}


But thats little screwed up, and takes a while for the ball to respond. I've just taken that code from a Flash CS5.5 demo, and just changed it a little, so it's probably not suited for what i want.
All i want to do is change world gravity with the accelerometer, a really simple thing but no one seems to be able to help with this anywhere! yet i know it's possible because i've seen it done many times. Please can someone help? I'm also using WCK for this, but i've got no help in the WCK forum. But being as WCK uses Box2D i would expect things to be the same for the most part...
Helpful for cory grant?
delete the "-"&"+"
{
//myWorld.gravityX-= event.accelerationX*9.8;
//myWorld.gravityY += event.accelerationY*9.8;
myWorld.gravityX= event.accelerationX*9.8;
myWorld.gravityY= event.accelerationY*9.8;
}
Beany wrote:How can i change gravity with a phones accelerometer? I have a ball inside a myWorld movieclip, and i want to move the ball around the stage using the accelerometer which controls the gravity, and so far i can get it to kind of work with something like this...

Code: Select all

var Accelerometer_3:Accelerometer = new Accelerometer();
Accelerometer_3.addEventListener(AccelerometerEvent.UPDATE, AccelerometerUpdate);

function AccelerometerUpdate(event:AccelerometerEvent):void
{
   myWorld.gravityX-= event.accelerationX*9.8;
   myWorld.gravityY += event.accelerationY*9.8;
}


But thats little screwed up, and takes a while for the ball to respond. I've just taken that code from a Flash CS5.5 demo, and just changed it a little, so it's probably not suited for what i want.
All i want to do is change world gravity with the accelerometer, a really simple thing but no one seems to be able to help with this anywhere! yet i know it's possible because i've seen it done many times. Please can someone help? I'm also using WCK for this, but i've got no help in the WCK forum. But being as WCK uses Box2D i would expect things to be the same for the most part...



where did you write that code?
inside the movieclip?
because i write it inside it and it didnt work :/

Original thread: https://box2d.org/forum/viewtopic.php?t=6976