Moving spaceship left or right

Talk about making games.

Moving spaceship left or right

Postby tvz » Wed Oct 08, 2014 12:23 pm

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?
Attachments
Untitled.jpg
I have not left.
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score

Re: Moving spaceship left or right

Postby skydereign » Thu Oct 09, 2014 7:25 am

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.
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Moving spaceship left or right

Postby tvz » Thu Oct 09, 2014 2:04 pm

you are awesome!
thankyou very much.
+1
I have not left.
User avatar
tvz
 
Posts: 98
Joined: Sun Mar 10, 2013 7:13 am
Location: Your PC screen
Score: 3 Give a positive score


Return to Game Development

Who is online

Users browsing this forum: No registered users and 1 guest