Point object towards another objects position

In my current project, i have a player object that i can move around the screen, im attempting to create a “turret” that i would like to rotate and point towards my player object, no matter where the player object moves too. I just cant seem to wrap my head around the mathematical part of how this might work, can anyone spread some insight? thank you [import]uid: 19620 topic_id: 15668 reply_id: 315668[/import]

Something like this will work :

[code]
local function checkAngle(obj1, obj2)
return math.ceil(math.atan2( (obj1.y - obj2.y), (obj1.x - obj2.x) ) * 180 / math.pi)
end

–Then for example (in a runtime or loop)
player.rotation = checkAngle(player, theTarget)

–You may need to offset it like so
player.rotation = checkAngle(player, theTarget) - 90
[/code] [import]uid: 84637 topic_id: 15668 reply_id: 57850[/import]

Thanks ill give that a try when i have a minute and let you know how it goes. [import]uid: 19620 topic_id: 15668 reply_id: 57862[/import]