Image Rotation on Accelerometer Event

Hello, I have a object

MyObject = display.newImageRect( "MyObject .png", 50, 50 ) MyObject .x = centerX MyObject .y = centerY
that moves with accelerometer event:

local function onAccelerate( event )  
 MyObject .x = centerX + (centerX \* event.xGravity)  
 MyObject .y = centerY + (centerY \* event.yGravity \* -1)  
 --- rotation angle????  
 local angle = ( math.atan2( MyObject .y - centerY , MyObject - centerX ) \* ( 180 / pi ) ) + 90  
 MyObject .rotation = angle  
end  

where

local centerX = display.contentWidth / 2  
local centerY = display.contentHeight / 2  

My question is how to set rotation angle properly so picture MyObject.png could follow movement of the object?
[import]uid: 65687 topic_id: 28409 reply_id: 328409[/import]

Take a look at this code, IIRC it worked; http://pastebin.com/fjqp3Ukw

Peach :slight_smile: [import]uid: 52491 topic_id: 28409 reply_id: 114745[/import]

Thanks Peach :slight_smile:

He did angle rotation exactly like me :slight_smile:

 angle = math.atan2(xGravity, yGravity)  
 angle = angle\*(180/pi)  
 playerRotate = ceil(360 - angle(xGravity, yGravity))  

Btw that code from your link is not working properly.

I was looking for a slightly better(or different) image rotation solution but this code will do the work.
[import]uid: 65687 topic_id: 28409 reply_id: 114854[/import]