Public Group

# 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.

## 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 on other sites
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):

Good luck,
Geoff

Thanks.

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633656
• Total Posts
3013186
×