Help!! Making an object rotate with the accelerometer

Hey guys i’m trying to get my player to rotate with the accelerometer, as well as move, and my brain has hit a brick wall. Any help would be really appreciated.

Here is my code

[lua]local playerMovement = function(event)

local player = player
local playerStats = playerStats
local accelerometerReady = accelerometerReady
local gameIsActive = gameIsActive

if accelerometerReady and gameIsActive then

local _yG = _yG
local _xG = _xG

local currentYvalue = remote.yGravity - _yG
local currentXvalue = remote.xGravity - _xG

local currentRotation = (math.deg(math.floor(currentXvalue/currentYvalue)))
player.rotation = currentRotation

local playerX = player.x
local playerY = player.y

player.x = playerX + (currentYvalue * 35)
player.y = playerY + (currentXvalue * 35)

end

end[/lua]

Ideally I would like my player to rotate slowly to match the direction. Not snap to it like it is currently doing. Also it seems like it is reaching 359 degrees and then if I need to move to 10 degrees it has to rotate anti-clockwise back. Making it very painful
Any ideas guys??

Cheers [import]uid: 26289 topic_id: 25455 reply_id: 325455[/import]

Man ok i’ve made some progress with a dirty hack but still struggling. Forgot to mention that i’m using Matthew Pringle’s awesome remote tool for the accelerometer so that what this is

[lua] local currentYvalue = remote.yGravity - _yG
local currentXvalue = remote.xGravity - _xG[/lua]
Here is my latest code but this is anything but smooth. My object, which is meant to be underwater, rotates roughly to the direction in which the accelerometer is tilted, but it is rough as

[lua] if accelerometerReady and gameIsActive then

local _yG = _yG
local _xG = _xG

local currentYvalue = remote.yGravity - _yG
local currentXvalue = remote.xGravity - _xG

local playerX = player.x
local playerY = player.y

player.x = playerX + (currentYvalue * 35)
player.y = playerY + (currentXvalue * 35)

– Calculate Angle

local currentRotation = ( math.atan2( currentYvalue , currentXvalue ) * ( 180 / math.pi )
) + 90
if currentRotation < 0 then currentRotation = 360 + currentRotation end

player.rotation = currentRotation

end[/lua] [import]uid: 26289 topic_id: 25455 reply_id: 103005[/import]

Have you solved the problem?
I am facing same problem here. Can you help me with the equation to calculate the angle? [import]uid: 104777 topic_id: 25455 reply_id: 124220[/import]

Have you solved the problem?
I am facing same problem here. Can you help me with the equation to calculate the angle? [import]uid: 104777 topic_id: 25455 reply_id: 124220[/import]