How to change the gravity based on the gyroscope rotation

I am developing a game where the player has to move a ball using a gyroscope. Until now I have done the following:

--gyroscope function local function onGyroscopeDataReceived( event ) local deltaRadiansX = event.xRotation \* event.deltaTime local deltaDegreesX = deltaRadiansX \* (180 / math.pi) local deltaRadiansY = event.yRotation \* event.deltaTime local deltaDegreesY = deltaRadiansY \* (180 / math.pi) ball:applyForce( deltaDegreesX\*4, -deltaDegreesY\*4, ball.x, ball.y ) end  

I want instead of applying force to the ball, to change the gravity of the scene so the ball will fall in the appropriate direction, I supposed that I have to use the physics.setGravity( gx, gy ) . I am not sure which dimension of the device x,y,z represent and if deltaRadians or deltaDegrees can be used in gx,gy. Any idea how is it possible to achieve gravity change using gyroscope?

Hi @avraammauridis,

Please inspect the Corona sample project “ShapeTumbler”, located in your local CoronaSDK application folder:

CoronaSDK > SampleCode > Physics > ShapeTumbler

Best regards,

Brent Sorrentino

I tried that, I used the 

function onTilt( event )     deltaDegreesXText.text =  (9.8\*event.xGravity)     deltaDegreesYText.text =  (-9.8\*event.yGravity)     --ball:applyForce( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ), ball.x, ball.y )     physics.setGravity( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ) ) end  

But after a while the things stop moving-dropping in the appropriate direction. Even in the sample project, I tried it in my phone and after some seconds things stop falling according to the gravity. Any idea?

Hi @avraammauridis,

Please inspect the Corona sample project “ShapeTumbler”, located in your local CoronaSDK application folder:

CoronaSDK > SampleCode > Physics > ShapeTumbler

Best regards,

Brent Sorrentino

I tried that, I used the 

function onTilt( event )     deltaDegreesXText.text =  (9.8\*event.xGravity)     deltaDegreesYText.text =  (-9.8\*event.yGravity)     --ball:applyForce( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ), ball.x, ball.y )     physics.setGravity( ( 9.8 \* event.xGravity ), ( -9.8 \* event.yGravity ) ) end  

But after a while the things stop moving-dropping in the appropriate direction. Even in the sample project, I tried it in my phone and after some seconds things stop falling according to the gravity. Any idea?