Triogonometry

Previous topic - Next topic

ampos

I have an object that has to pursue the mouse. Currently I am using

delta.X=sgn(mouse.x-pos.x)
delta.Y=sgn(mouse.y-pos.y)

But this make it moving just in 45º steps, so it ended forming a "cross"

Then I imagine I have to use SIN and COS to calculate delta.x and delta.y, but right now I am a bit dull and dont know how to calculate the angle between the source (my sprite) and target (the mouse)

It should to start as

vector.x=mouse.x-pos.x
vector.y=mouse.y-pos.y

To get a vector starting point of 0,0...

But I have said, I am a bit dull right now.

ampos

Nevermind, I found it: ATAN

angle=ATAN(mouse.x-pos.x,mouse.y-pos.y)
delta.x=cos(angle)
delta.y=sin(angle)