Hi im making a game and I am struggling to get the maths right for a function im writing to move a object/vector around another object/vector in a circular movement. I have the function working ok except for one thing, which is the correct value to set my increment variable to start my circular movement.

Let me show you the function and it should make more sense.

Code:

local radius = 140 -- Radius of the circle
local cosCounter = 0 -- starting point of the cosCounter
local spinAround = function(self,tDelta,targetY,targetX)
object.x = math.sin(cosCounter)*radius + targetX
object.y = math.cos(cosCounter)*radius + targetY
cosCounter = cosCounter - tDelta* 0.01 -- speed of the object ( + is clockwise )
return
end

Can someone please tell how I can set the value cosCounter to be at the same position as my object from x/y coords, which will be some where along the radius of the target???

Many thanks.