Combining Accelerometer Instant With Gravity

Hi there,

My goal is to let the instant values of the accelerometer decide the direction of my player object (a ball) and let the accelerometer gravity hold that direction as the Instant will fall back to a value of 0 if I hold my phone in a set position.

How it looks right now without the combination

local function onAccelerate( event ) if event.yInstant \> 0.05 then physics.setGravity(-12, 16) else if event.yInstant \< -0.05 then physics.setGravity(12, 16) else physics.setGravity (0, 16) end end end

Help/reflections is much appreciated :slight_smile:

I’m still stuck with this, anyone have any of their own reflections on how to solve this? It absolutely does not have to be code. Without the right effect on the accelerometer I’m afraid I need to rework the whole concept of my game, which is the last thing I would like to happen  :frowning:

Such a miss, after some time away I decided to retry and think easy. All this time I’ve been thinking complicated while this code really covers the “basics” of what I’ve been thinking to accomplish:
 

local function onAccelerate( event ) if event.yInstant \> 0.1 then physics.setGravity(-12, 16) elseif event.yInstant \< -0.1 then physics.setGravity(12, 16) elseif event.yGravity \> 0.1 then physics.setGravity(-12, 16) elseif event.yGravity \< -0.1 then physics.setGravity(12, 16) else physics.setGravity (0, 16) end end

Previously as the yInstant value went below the limit I set up, the only case left was the ‘else’ case, which was the 0 case. What happens now is that the physics.setGravity first reacts to my yInstant limits (< -0.1 and > 0.1 ), as they fall back to 0 the yGravity values have had enough time to reach their actual value in the fixed position of the phone, making the two last “elseif” cases viable.

Now there still is some things you can do to improve this idea, but I’ll just leave the basic (stupidly easy) solution here.

I’m still stuck with this, anyone have any of their own reflections on how to solve this? It absolutely does not have to be code. Without the right effect on the accelerometer I’m afraid I need to rework the whole concept of my game, which is the last thing I would like to happen  :frowning:

Such a miss, after some time away I decided to retry and think easy. All this time I’ve been thinking complicated while this code really covers the “basics” of what I’ve been thinking to accomplish:
 

local function onAccelerate( event ) if event.yInstant \> 0.1 then physics.setGravity(-12, 16) elseif event.yInstant \< -0.1 then physics.setGravity(12, 16) elseif event.yGravity \> 0.1 then physics.setGravity(-12, 16) elseif event.yGravity \< -0.1 then physics.setGravity(12, 16) else physics.setGravity (0, 16) end end

Previously as the yInstant value went below the limit I set up, the only case left was the ‘else’ case, which was the 0 case. What happens now is that the physics.setGravity first reacts to my yInstant limits (< -0.1 and > 0.1 ), as they fall back to 0 the yGravity values have had enough time to reach their actual value in the fixed position of the phone, making the two last “elseif” cases viable.

Now there still is some things you can do to improve this idea, but I’ll just leave the basic (stupidly easy) solution here.