Eyes to look at touched spot!

Hi,
I am trying to create a function where an eye is looking at the direction where the player taps.

i am not a mathematic genius so some help would be great!

display.newCircle( 200, 200, 110 )  
  
local object = display.newCircle( 200, 290, 20 )  
object:setFillColor(128,128,128)  
  
local originX,originY = 200,200 -- Center position of the circle   
   
local radius = 100 -- Radius of the circle  
   
local cosCounter = 0 -- position of the object thats going to move around the circle  
 -- each lap takes math.pi\*2  
   
function enterFrame()  
   
 object.x = math.sin(cosCounter)\*radius + originX  
 object.y = math.cos(cosCounter)\*radius + originY  
   
 cosCounter = cosCounter + -0.3 -- speed of the object ( + is clockwise )  
   
   
end  
  
function check( event )  
  
 local playerangle = math.floor(180-math.atan2(event.x - object.x, event.y - object.y)\*(180/math.pi))   
 object.x = ??  
 object.y = ??  
end   
--Runtime:addEventListener("enterFrame",enterFrame)  
Runtime:addEventListener("tap", check)  

Regards, Joakim [import]uid: 81188 topic_id: 21645 reply_id: 321645[/import]

This related to drag not tap but may be useful; http://developer.anscamobile.com/forum/2011/04/20/how-rotate-turret-dragging

I’m not a mathematician either :wink: [import]uid: 52491 topic_id: 21645 reply_id: 86055[/import]

Hi Joakim

did you find a solution to this? If you did, would you mind share your solution with me?

Thank you in advance :slight_smile:

Best regards
Se460 [import]uid: 122802 topic_id: 21645 reply_id: 97130[/import]

Yepp, I did found a solution but I don’t have it left, since we used another approach. I was rotating the eyes as I remember and it worked for 90% but it did rotate the opposite way, when the angle was over 360 degree - if i remember it correctly.

Joakim [import]uid: 81188 topic_id: 21645 reply_id: 97133[/import]