Jump to content
  • Advertisement
Sign in to follow this  
Darobat

Propper Movement *SOLVED*

This topic is 4969 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings. I'm not quite sure how I would make a game where you would actually travel in the direction you are facting... If your traveling at 0, 90, 180 etc. its easy, but how would I figure out how much to move the player on the x and y axis' if he was moving at a 58° angle? Thanks. [Edited by - Darobat on November 11, 2004 10:21:25 AM]

Share this post


Link to post
Share on other sites
Advertisement
Learn some basic math and trig and you will be off to a good start. To get you started:

x += cos(angle) * speed;
y += sin(angle) * speed;

Note that the angle should be in radians.

Share this post


Link to post
Share on other sites
Greetings,
I tried implementing your suggestion but it so far is unsuccesful. Heres what I have:
if(keys[VK_UP])
{
guy.y += sin(DEG_TO_RAD(guy.rot));
guy.x += cos(DEG_TO_RAD(guy.rot));
}
else if(keys[VK_DOWN])
{
guy.y -= sin(DEG_TO_RAD(guy.rot));
guy.x -= cos(DEG_TO_RAD(guy.rot));
}


When I have an angle of 0 I move left and right. not up and down. DEG_TO_RAD is defined as #define DEG_TO_RAD(x) (x * (180 / 3.14159)) Any ideas? Thanks.

Share this post


Link to post
Share on other sites
Ooook... 0° makes me move down. 90° moves me correctly. 180° moves me up. 45° moves me 135°. The closer I get to 90° the more accurate it is...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!