Pointing one sprite in the direction of another

BlitzMax Forums/BlitzMax Programming/Pointing one sprite in the direction of another

I wrote this function (as show below) to use in pointing the enemies in my Geometry Wars-like game toward the player. Unfortunately, I can find no errors in the code that would cause it to return -1.#IND0000 no matter what the points entered.

Function Rotate#(x0,y0,x1,y1)
	Local lega#,legb#,hypc#
	Local ang#,CosA#
	
	lega=Abs(x0-x1);legb=Abs(y0-y1) 'Get legs
	hypc=Sqr(lega^2+legb^2) 'Get hypotenuse
	CosA=hypc/legb 'Get cosine of angle
	ang=ASin(CosA) 'Get degrees in angle

	Return ang
End Function



Can anyone spot my error?

If the y coordinates are ever the same, you're going to run into a divide by zero operation. Not sure if that's your problem or not though.

Yea, good point. I'd probably get a nasty headache later on if I hadn't figured that out now. Thanks for that.


[edit] just realized that I had ASin where I should have had ACos, but changing this had no affect on the returned value.


[edit 2] I found the problem. Dummie me put leg/hypotenuse rather than hypotenuse/leg -.-