So I've been looking for a way to get a sprite to rotate and face my cursor, and I came across this:
You wan't a sprite to point towards the mouse pointer?
If that is the case you would probably need a algorithm to calculate it. It would depend on the location of the sprite as much as of the mouse pointer.
Let´s say the rotation 0 is straight up then that should be the case when it has the same X as mouse and Y is bigger.
The math here would be, assuming:
pos is position of sprite
mouse is position of mouseDeltaY = mouse.Y - pos.Y
DeltaX = mouse.X - pos.Xrotation = tan^-1(DeltaY / DeltaX)
Now I understand that it works, but I'm wondering if one of you fine people can help me understand why it works. I'm not that great at math, but I take every chance I can to improve. I need to understand the concept behind tan, and inverse tan, so I can apply it to any other problems I might face that would require it.
Thanks
Just to clarify, I know what tan is. Tan = opposite / adjacent. I know you feed tan the angle, and it returns o/a but why is o/a needed? What is it used for? and I don't know what inverse tan is at all.