Help With Smooth Accelerometer Controls

Hello and thanks for looking at this post. 

 

I am having trouble writing a smooth accelerometer control function. Right now, because it’s sensing for tilt greater than 0, it gives off a sudden stop/jerk when switching directions. I tried looking at some simple examples online but the results were not smooth at all and problematic. Does anyone have any suggestions how to avoid the jerkiness and keep smoothness when the character moves? 

 

Here is the code:

 

 

local function onTilt( event )     local u,v = player:getLinearVelocity() local tilt = event.yGravity local newDirection = 0 if math.abs(tilt) \> .1 then newDirection = tilt/math.abs(tilt)         player:setLinearVelocity(-newDirection\*200,v) else         player:setLinearVelocity(0,v) newDirection = 0 end direction = newDirection end  

 

 

Thanks!!!

Any help or suggestions on how to write better controls would be great! 

 

Thanks

There is this API call:

[lua]

     system.setAccelerometerInterval( 30 )

[/lua]

 

That helps adjust the Accelerometer.  This number should probably match your FPS frame rate (30 or 60)

 

Thanks for the reply! 

 

Where would this API call go? Would it fall under the tilt function or in the configuration file? 

 

Thanks, 

Marc

I ended up putting the call in the main lua file - the accelerometer controls are now smooth as butter - Thanks Rob!

Any help or suggestions on how to write better controls would be great! 

 

Thanks

There is this API call:

[lua]

     system.setAccelerometerInterval( 30 )

[/lua]

 

That helps adjust the Accelerometer.  This number should probably match your FPS frame rate (30 or 60)

 

Thanks for the reply! 

 

Where would this API call go? Would it fall under the tilt function or in the configuration file? 

 

Thanks, 

Marc

I ended up putting the call in the main lua file - the accelerometer controls are now smooth as butter - Thanks Rob!