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

## 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 on other sites
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 on other sites
Thats what I was thinking but I wasn't sure if that would actuall work. Thanks.

##### 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 on other sites
Try changing the DEG_TO_RAD(x) to (x*(PI/180)).

##### Share on other sites
lol, I new it was something stupid.

##### Share on other sites
That didn't change anything... :( Al the angles are 90° off CW.

##### Share on other sites
When you have an angle of 0, the cos value is 1 so you will move left and right, to counter that effect just swap the sin and cos.

##### 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 on other sites
ok, so did that work out . . . you still having problems or is it all good now?

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631375
• Total Posts
2999659
×