Problem with controlling character using Accelerometer

Hello, I am trying to control my character by tilting the phone side to side and up & down but there seems to be some issues.  It works ok in the beginning but after a few minutes, the character becomes unresponsive and starts going in any direction it wants.

Here is a snippet of my code for controlling the character:

local character = display.newImageRect( “character.png", 33, 36 ) character.x, character.y = 200, 320 local tiltSpeed = 35; local motionx = 0; local motiony = 0; local rotation = 0; local delta = -40/180\*math.pi local delta2 = 0/180\*math.pi local cos\_delta, sin\_delta = math.cos(delta), math.sin(delta) local cos\_delta2, sin\_delta2 = math.cos(delta2), math.sin(delta2) local function onTilt(event) motiony = tiltSpeed \* (cos\_delta\*event.xGravity + sin\_delta\*event.zGravity) motionx = tiltSpeed \* (cos\_delta2\*event.yGravity + sin\_delta2\*event.zGravity) end

The Up and Down accelerometer control works great by itself (local delta = -40/180*math.pi) but when I add in the next line of code for the Side to Side control (local delta2 = 0/180*math.pi), thats when the code seems to break and I lose control of my character.

I’m wondering if I’m even doing this correctly.  The (local delta) line of code was from a tutorial I saw sometime ago for controlling Up and Down, and I guessed by adding in (local delta2) might work for Side to Side but I’m thinking they’re not meant to be used together like that.  Would anyone know of a better way? 

Thanks!

Star