Rotating an object with Accelerometer

Can anyone help me with the equation for rotating an object with accelerometer?
Currently I am trying with

rotation = math.atan2(e.xGravity, e.yGravity);  
rotation = rotation\*(180/math.pi);  

But it doesn’t look realistic. I tried xInstant and yInstant. But they are too faster and the object always moves… Any idea? [import]uid: 104777 topic_id: 30925 reply_id: 330925[/import]

I’m not in front of Corona machine to test it on. Can you explain “doesn’t look realistic?”

Instead of forcing the rotation to the exact value, you might want to try a transition. This is what I think the code could look like off the top of my head:if rotationtrans then transition.cancel( rotationtrans ) end newrotation = math.atan2( e.xGravity, e.yGravity ) \* ( 180 / math.pi ) rotationtrans = transition.to( object, { time = 1000, rotation = newrotation, transition = easing.inExpo } )

Of course, you can change the time from 1000 ms to anything, as well as the easing method, such as easing.outExpo, easing.inQuad, easing.outQuad, etc.

Let me know if that helps. [import]uid: 6084 topic_id: 30925 reply_id: 123679[/import]

Thanks for your reply.
Here the yGravity and xGravity is 0 0 when the phone is in stable state. When I rotate it downward, yGravity starts to increase and when my character is in the bottom of the screen it is nearly 2.5 and the character is looking downward. Now when I rotate it upward the yGravity starts decreasing. So the characters rotation changes to upward after a long time. But I want it instant.
What should I do?
I can give you an example. There is a game called Lady Bug. I want to make the movement of my game character just like the character in that game. Can you help me please?
[import]uid: 104777 topic_id: 30925 reply_id: 123683[/import]

I think if I can use xInstant ans yInstant anyway it will help. :confused: [import]uid: 104777 topic_id: 30925 reply_id: 123684[/import]

I’m not in front of Corona machine to test it on. Can you explain “doesn’t look realistic?”

Instead of forcing the rotation to the exact value, you might want to try a transition. This is what I think the code could look like off the top of my head:if rotationtrans then transition.cancel( rotationtrans ) end newrotation = math.atan2( e.xGravity, e.yGravity ) \* ( 180 / math.pi ) rotationtrans = transition.to( object, { time = 1000, rotation = newrotation, transition = easing.inExpo } )

Of course, you can change the time from 1000 ms to anything, as well as the easing method, such as easing.outExpo, easing.inQuad, easing.outQuad, etc.

Let me know if that helps. [import]uid: 6084 topic_id: 30925 reply_id: 123679[/import]

Thanks for your reply.
Here the yGravity and xGravity is 0 0 when the phone is in stable state. When I rotate it downward, yGravity starts to increase and when my character is in the bottom of the screen it is nearly 2.5 and the character is looking downward. Now when I rotate it upward the yGravity starts decreasing. So the characters rotation changes to upward after a long time. But I want it instant.
What should I do?
I can give you an example. There is a game called Lady Bug. I want to make the movement of my game character just like the character in that game. Can you help me please?
[import]uid: 104777 topic_id: 30925 reply_id: 123683[/import]

I think if I can use xInstant ans yInstant anyway it will help. :confused: [import]uid: 104777 topic_id: 30925 reply_id: 123684[/import]