Tilt left right code

Hi Coronaville :slight_smile:

Can somebody please share tilt go left/right code, so I do not have to invent it from scratch?

Many gracias!
GG

But where is the fun in that? Learning how to do things leads to strong programmer-force.

To get you started, I used something like this in my space shooter where tilting moves the player left/right:

local function onTilt(event) myRocket.x = (myRocket.x + event.xGravity \* ((sensitivity \* 15 )+ level)) if myRocket.x \< 0 then myRocket.x = 0 elseif myRocket.x \> (display.contentWidth - 64) then myRocket.x = display.contentWidth - 64 end return true end Runtime:addEventListener("accelerometer", onTilt )

Or something similar.

Thanks Rob.
I will play around with this :slight_smile:

what exactly is the sensitivity and level in the code just to get an understanding of the code better

In my game “level” is the current game level. It’s a number of 1 to around 25 or so. I want the player to have a little faster movement as play progresses. The player can also set a difficulty level (1 - 3). It’s harder to control moving quickly, so this lets me ramp up the speed.

Rob

But where is the fun in that? Learning how to do things leads to strong programmer-force.

To get you started, I used something like this in my space shooter where tilting moves the player left/right:

local function onTilt(event) myRocket.x = (myRocket.x + event.xGravity \* ((sensitivity \* 15 )+ level)) if myRocket.x \< 0 then myRocket.x = 0 elseif myRocket.x \> (display.contentWidth - 64) then myRocket.x = display.contentWidth - 64 end return true end Runtime:addEventListener("accelerometer", onTilt )

Or something similar.

Thanks Rob.
I will play around with this :slight_smile:

what exactly is the sensitivity and level in the code just to get an understanding of the code better

In my game “level” is the current game level. It’s a number of 1 to around 25 or so. I want the player to have a little faster movement as play progresses. The player can also set a difficulty level (1 - 3). It’s harder to control moving quickly, so this lets me ramp up the speed.

Rob