Page 1 of 1

Moving spaceship left or right

PostPosted: Wed Oct 08, 2014 12:23 pm
by tvz
Hello
i need help. i am making a spaceship which moves in mouse's direction (and rotates also).
it is possible to make it move perpendicular to the direction of mouse?

Re: Moving spaceship left or right

PostPosted: Thu Oct 09, 2014 7:25 am
by skydereign
tvz wrote:it is possible to make it move perpendicular to the direction of mouse?

With angles this is pretty easy.
Code: Select all
char* key = GetKeyState();
double ang = direction(xscreen, yscreen, xmouse, ymouse); // this gets the angle towards the mouse
// your rotation code would go here using ang

angle = ang + (key[KEY_RIGHT] - key[KEY_LEFT])*90; // plus or minus 90 of the direction to the mouse to make it perpendicular
directional_velocity = (key[KEY_RIGHT] || key[KEY_LEFT]) * 5; // 5 being the speed you want it to move

Note though that this will cause the player to rotate around the mouse if you put that in the draw actor event, as ang is constantly being updated. If you don't want that, then only update ang when you need to. You could also use the trig functions sin/cos to do this.

Re: Moving spaceship left or right

PostPosted: Thu Oct 09, 2014 2:04 pm
by tvz
you are awesome!
thankyou very much.
+1