Rotating (or any other direct manipulation) of a physics object can be done in one of three different ways. None of these allow you to update the rotation or position of the physics body like you would a regular display object because you would be fighting the Box2D physics engine. To operate on objects in the physical world you must adhere to the rules of the physical world…
#1 - Directly: Turn off the physics body with .isBodyActive and manipulate the display object, then turn the physics body back on.
#2 - Fake touch: Connect a touch joint to the body and programmatically move the touch joint. This simulates a user’s touch, but is more precise because your code controls the motion. Increase the amount of max force to reduce the inaccuracy and make it look more explicit.
#3 - Motor: Assuming you want a motion that can be performed with a motor, just attach a joint to the body and use the motor. This is rather imprecise and can take a lot of fiddling around. If you don’t mind other objects colliding with the body and messing with the effect the joint’s motor is having on the body, you’ll be fine. Remember: the more force, the faster it will move - it’s simply not as controlled as the fake touch method.
IMHO: Fake touch. It’s got a high degree of control, provides better motions than a joint motor can (you can move things anywhere) and you don’t have to stop your body from affecting others.
Your problem: If I were you, I would attach a pivot to the point on your body where you want it to rotate around. Then attach a touch joint somewhere on the edge of the body. Use a simple bit of maths to rotate the touch joint smoothly and just keep updating the touch joint every frame.
The code below creates a square, attaches a touch joint to it and uses a display group (without physics) to calculate the rotation of the touch joint. An anchor body is used to keep the image in place. The solution avoids the need to use your own rotation calculations. It also uses a enterFrame listener to rotate the square and removes the listener when the rotation transition has finished.
require("physics") physics.start() physics.setGravity(0,10) local anchor = display.newCircle( -100,-100,10 ) physics.addBody(anchor,"static") local rect = display.newRect(0,0,200,200) rect.x, rect.y = display.contentCenterX, display.contentCenterY physics.addBody(rect,"dynamic") local pivotjoint = physics.newJoint("pivot",anchor,rect,display.contentCenterX, display.contentCenterY) local touchjoint = physics.newJoint("touch",rect,display.contentCenterX+200, display.contentCenterY) local easyturn = display.newGroup() easyturn.x, easyturn.y = display.contentCenterX, display.contentCenterY function enterFrame() local x, y = easyturn:localToContent(200,0) touchjoint:setTarget(x,y) end transition.to( easyturn, {time=10000,rotation=360, onComplete=function() Runtime:removeEventListener("enterFrame",enterFrame) end} ) Runtime:addEventListener("enterFrame",enterFrame)