Need Help making a Image look at cursor.

BlitzMax Forums/BlitzMax Beginners Area/Need Help making a Image look at cursor.

Labenex(Posted 2011) [#1]
Hey! I'm having a little bit of trouble making my image "look" at the cursor. I have tried Atan2 but with no success.
Here is the code for Atan2:
SetRotation(ATan2(-MouseY(), MouseX()))

Any help is appreciated.


Kryzon(Posted 2011) [#2]
Atan2 can output the angle between two points on the screen if you supply the difference between them - this angle can be seen as 'how much object A has to rotate to face object B' (the Blitz3D documentation on this command is a bit more thorough than the BlitzMax one):
'At the initialization part of your code.
MidHandleImage Image 'Handle your image by the center.

'[...]

'At render time:
SetRotation( Atan2( MouseY() - ImageY, MouseX() - ImageX) )
DrawImage Image,ImageX,ImageY 'ImageX and ImageY are the coordinates you use to center your image on the screen.
Tell me if that works.
You might need to add a certain offset to the value returned by Atan2 (like -90 or something like that), if your image spins with the cursor but is facing the wrong way.

Last edited 2011


Labenex(Posted 2011) [#3]
Thank you very much! It works!