making an image face the mouse

Blitz3D Forums/Blitz3D Beginners Area/making an image face the mouse

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

EDIT: use ATan2() instead, it does all of this for you.

To get the angle from one point to another, subtract and use arctan:
	Local dir#
	Local dx# = p\x - MouseX()
	Local dy# = p\y - MouseY()
	If dy < 0 Then dir = ATan(dx/dy)
	If dy > 0 Then dir = ATan(dx/dy) + 180
	If dy = 0 Then ; don't divide by 0!
		If dx < 0 Then dir = 90 Else dir = 270
	EndIf

I snagged this from some of my code in an old discussion about Plobb. There may be a more elegant approach.