Rotate an object like a wheel using touch

I want to touch an object and rotate it clockwise or anticlockwise based on the touch’s x&y:

  function rotatePlayer(event)    local obj = event.target     if (event.phase == "began") then     display.getCurrentStage():setFocus( obj )         obj.startX = (event.x - obj.x)     obj.startY = (event.y - obj.y)      obj.startAngle = math.atan2( obj.startY, obj.startX ) \* (180 / math.pi)     elseif (event.phase == "moved") then     local dX = (event.x - obj.x)     local dY = (event.y - obj.y)  local angle = math.atan2( dY, dX ) \* (180 / math.pi)     local dAngle = (angle - obj.startAngle)     obj.rotation = dAngle         elseif (event.phase == "ended") then     end   end

The result is not as expected, some jerky movement and not consistent with the touch’s gesture.  Any help would be appreciated.

https://forums.coronalabs.com/topic/65202-rotating-issue/Like this?

** UPDATE - I won’t be following up any further on this answer, everything you need is in the answer pack **

I definitely answered this in one of my answer packs:

http://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015%20Answer%20Packs

However, scott’s answer may be more accesible to you as mine uses math2d (plugin/lib)

http://www.youtube.com/watch?v=18TxGiun8Jc&t=1m29s

It’s not different than my code other than subtracting the angle:

adjustment = math.atan2(dy,dx) \* 180 / PI - ball.rotation \<\<- here ball.rotation = (math.atan2(dy,dx) \* 180 / PI) - adjustment \<\<- and here

But the result is still the same, it’s not working as intended for me. 

Any help would be appreciated here guys, I’m not sure if the problem is with my calculation ( most likely not because I have the same calculation working in SpriteKit) or with the way Corona handles the touch events. 

The demo works fine on my computer, what is your fps set on?

https://www.dropbox.com/sh/oh3wzps9datd5a3/AAAxPsP4T7PENFB3Px362D0Ra?dl=0

First of all, let me thank you for your effort.

Second, your FPS question  ( which I set to 60 btw) inspired me to test the game on my device, the games (both yours and mine)  work perfectly on the device but not in the Corona simulator.  I don’t know why despite having both Xcode and Unity run perfectly fine on my machine, granted that it’s not new or powerful ( 2013 MacBook Air) but heavier simulators work fine on it. 

In the simulator, there is a lot of stuttering and jerky movement, and it’s like the object is not following the touch 1:1 

i am on a macbook pro 2012 and it works fine in simulator. Macbook airs are usually not a powerful pros. But you still should not being that much stuttering on a 2013 air. What version of corona are you running? What are your specs on your computer (can be found by clicking apple icon in top left and about this mac)?

It may be a ram problem, but i am not sure. Try turning you computer on and off. Fun fact apple recommends doing this once a week to clear out memory leaks.

Yes, restarting definitely helped. I was worried for a while there because both Lua & Corona are supposed to be very lightweight. 

https://forums.coronalabs.com/topic/65202-rotating-issue/Like this?

** UPDATE - I won’t be following up any further on this answer, everything you need is in the answer pack **

I definitely answered this in one of my answer packs:

http://github.com/roaminggamer/RG_FreeStuff/tree/master/AskEd/2015%20Answer%20Packs

However, scott’s answer may be more accesible to you as mine uses math2d (plugin/lib)

http://www.youtube.com/watch?v=18TxGiun8Jc&t=1m29s

It’s not different than my code other than subtracting the angle:

adjustment = math.atan2(dy,dx) \* 180 / PI - ball.rotation \<\<- here ball.rotation = (math.atan2(dy,dx) \* 180 / PI) - adjustment \<\<- and here

But the result is still the same, it’s not working as intended for me. 

Any help would be appreciated here guys, I’m not sure if the problem is with my calculation ( most likely not because I have the same calculation working in SpriteKit) or with the way Corona handles the touch events. 

The demo works fine on my computer, what is your fps set on?

https://www.dropbox.com/sh/oh3wzps9datd5a3/AAAxPsP4T7PENFB3Px362D0Ra?dl=0

First of all, let me thank you for your effort.

Second, your FPS question  ( which I set to 60 btw) inspired me to test the game on my device, the games (both yours and mine)  work perfectly on the device but not in the Corona simulator.  I don’t know why despite having both Xcode and Unity run perfectly fine on my machine, granted that it’s not new or powerful ( 2013 MacBook Air) but heavier simulators work fine on it. 

In the simulator, there is a lot of stuttering and jerky movement, and it’s like the object is not following the touch 1:1 

i am on a macbook pro 2012 and it works fine in simulator. Macbook airs are usually not a powerful pros. But you still should not being that much stuttering on a 2013 air. What version of corona are you running? What are your specs on your computer (can be found by clicking apple icon in top left and about this mac)?

It may be a ram problem, but i am not sure. Try turning you computer on and off. Fun fact apple recommends doing this once a week to clear out memory leaks.