OK guys, I know how to use mousex and mousey, so I got a question:
How can I make the ship always move in a straight line towards the mouse? making it go to the mouse x and y is easy, and I tried having X and Y velocities but that's awkward and floaty.
Gan, I bet you know this one! I NEED some help here!
Simpler version:
How to move sprite A a certain distance straight towards a point on the screen.
EDIT: Here's one example of the math (in Action Script). Both programs move the object at a fixed speed towards a point.
http://www.gamedev.net/community/forums/topic.asp?topic_id=564343There's 2 ways to do it. In #1 I can re-create everything but the function "atan2" because I'm not sure how it uses the 2 values.
If I can't emulate that perhaps there's a chance I can use the second version?
EDIT #2:
I used this code and the ship follows the mouse, but ONLY if the mouse x and y are greater than the ship's x and y.
Still, pretty cool that it works when the mouse is below and to the right of the ship.
How can I make it work in any direction?
LET speed=44
LET fY = mouseY-shipY
LET fX = mouseX-shipX
LET dist = sqrt( fX*fX + fY*fY )
LET step = speed/dist
LET shipX=shipX+(fX*step)
LET shipY=shipY+(fY*step)