touch based rotation

i want my character to aim at were i click, but the results i am getting are wierd.
could i get a little help.
here is the code:
[lua]local physics = require(“physics”)
local gameUI = require(“gameUI”)
physics.start()
physics.setGravity( 0, 0 )

firefighter = display.newImage( “fireman.png”,400,720)
physics.addBody( firefighter, { density = 200000,friction=0, bounce=0,radius=25} )

function rotatingTheFirefighter(event)
a=firefighter.y-event.y
b=event.x-firefighter.x
goalRotation= math.deg(math.atan(a/b))
if event.phase==“began” then
transition.to(firefighter, { time=15, rotation = goalRotation })
elseif event.phase==“moved” then
transition.to(firefighter, { time=15, rotation = goalRotation })
end
end
Runtime:addEventListener(“touch”, rotatingTheFirefighter)[/lua]

thanks in advance :stuck_out_tongue: [import]uid: 28068 topic_id: 7460 reply_id: 307460[/import]

This code will work for when you “move”. You need to figure out your original image orientation angle and then rotate accordingly for the “began” phase.

local prevAngle = 0;  
  
function rotatingTheFirefighter(event)  
  
goalRotation= math.atan2(firefighter.y-event.y,firefighter.x-event.x); -- math.deg(math.atan(a/b))  
goalRotation= (goalRotation \*180) / 3.14159767598  
  
if event.phase=="began" then  
 -- find initial orientation of your image, then rotate accordingly.  
elseif event.phase=="moved" then  
  
 firefighter:rotate(goalRotation-prevAngle);  
  
end  
prevAngle = goalRotation  
  
end  

Runtime:addEventListener(“touch”, rotatingTheFirefighter) [import]uid: 24 topic_id: 7460 reply_id: 26509[/import]

thanks a ton ;p [import]uid: 28068 topic_id: 7460 reply_id: 26943[/import]