Jump to content
  • Advertisement
Sign in to follow this  
spyfire

Moving object

This topic is 3663 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

Hi, i know how to move a object in 2d but in a way it's not moving in the right direction, so can anyone please help with this one and tell me what is not correct. void Ship::Tick(){ //get keyboard arrow short key_up, key_down, key_left, key_right; key_up = GetAsyncKeyState(VK_UP); key_down = GetAsyncKeyState(VK_DOWN); key_left = GetAsyncKeyState(VK_LEFT); key_right = GetAsyncKeyState(VK_RIGHT); if(key_up){ speed = 1; } if(key_down){ speed = -1; } if(!key_up && !key_down) speed = 0; if(key_right){ if(t_move-- <= 0){ if(angle < 360) angle += 11.25; t_move = 20; }; } if(key_left){ if(t_move-- <= 0){ if(angle > 0) angle -= 11.25; t_move=20; }; } x += cos(angle)*speed; y += sin(angle)*speed; };//tick

Share this post


Link to post
Share on other sites
Advertisement
Hi,

The functions sin() and cos() take the angle in radians, not in degrees. To convert from degrees to radians, divide by 180.0 and multiply by pi.

If you want to know more about radians, Wikipedia has a long article (that I didn't read):

http://en.wikipedia.org/wiki/Radians

Good luck,
Geoff

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!