How to caclulate an angle?

BlitzMax Forums/BlitzMax Programming/How to caclulate an angle?

I want to point an object to the mouse pointer in the correct angle, but it seems that something is wrong with my formula I use, because the rectangle doesn't point in the exact direction sometimes. Also sometimes it complelty disappears from the screen.

Here's the code


Graphics 640,480

Local x:Float = 320
Local y:Float = 240

Local Angle:Float = 0

While (1)
	Cls
		
	Angle = ASin((MouseX() - x) / (y - MouseY()))
	SetRotation(Angle)
	DrawRect x-20,y-20,40,40
	SetRotation(0)
	DrawLine (x,y,MouseX(),MouseY())
	
	Flip
Wend