Rotation problem with tap movement(RPG Like)

I had some problem with rotation of the object.

The problem is when i move forward to x and y axis object rotation is okey, but if i move backward on x and y axis object dont rotate, can someone help me?

here’s the line of code for rotation

--destx and desty tapped area on the screen xDistance = destx - obj.x yDistance = desty - obj.y obj.rotation = math.deg(math.atan(yDistance / xDistance))

Im new to corona and i dont know some functions.

Regards, Joro

Hi Joro, 

Have you seen this tutorial on pinch, zoom and rotate? http://www.coronalabs.com/blog/2013/01/22/implementing-pinch-zoom-rotate/#comment-25508

It works great! Thanks to HoraceBury for making it available. It is super. Take a look if you haven’t and I’m sure you will be able to solve your problem.

Regards,

Kerem

Still cant solve my problemE

EDIT:

Fixed!

 xDistance = destx - obj.x yDistance = desty - obj.y local angle = math.deg(math.atan2(yDistance, xDistance)) obj.rotation = angle

instead of:

xDistance = destx - obj.x yDistance = desty - obj.y obj.rotation = math.deg(math.atan(yDistance / xDistance))

its need to be math.atan2 not atan IMO i hope somebody can use it

Great news!!! Thanks for posting your solution. I am sure it will help someone else along the way! Great work.

Hi Joro, 

Have you seen this tutorial on pinch, zoom and rotate? http://www.coronalabs.com/blog/2013/01/22/implementing-pinch-zoom-rotate/#comment-25508

It works great! Thanks to HoraceBury for making it available. It is super. Take a look if you haven’t and I’m sure you will be able to solve your problem.

Regards,

Kerem

Still cant solve my problemE

EDIT:

Fixed!

 xDistance = destx - obj.x yDistance = desty - obj.y local angle = math.deg(math.atan2(yDistance, xDistance)) obj.rotation = angle

instead of:

xDistance = destx - obj.x yDistance = desty - obj.y obj.rotation = math.deg(math.atan(yDistance / xDistance))

its need to be math.atan2 not atan IMO i hope somebody can use it

Great news!!! Thanks for posting your solution. I am sure it will help someone else along the way! Great work.