I've come to a point in my game where I need to calculate an angle depending on the X,Y values of the mouse relative to a given point. The first thing I did was try to reverse engineer the CalculateVector() function found in V2SpaceShooter.kpl. Didn't work. =/ Next I tried using Math.ArcCos for the X value and Math.ArcSin for the Y value. I get a few intelligible numbers when the mouse is close to ( 1-2 pixels away from ) the screen edge. Anywhere else and I get a cryptic "NaN" value. Huh? What does "NaN" mean? And why do ArcCos and ArcSin return it as a number?
Mostly though, how do I use ArcCos or ArcSin to calculate an angle of a line ( or Vector ) that stretches from point A to point B, assuming that I will get 0 if B.x = A.x and B.y < a.Y (In other words, a line that goes from 0,0 to 0,10 will give me an angle of 180, and a line from 0,10 to 0,0 gives the angle of 0)?
PS. If that was hard to understand, I can try to think up a few more examples.