Propper Movement *SOLVED*

Started by
16 comments, last by Darobat 19 years, 5 months ago
for one thing, you aren't modifying the value of guy.rot. You should rotate the guy by changing this value...not by changing the sign of the equations.

instead you should do something like;

if(keys[VK_UP]){   guy.rot += 2; //2 is just an example}else if(keys[VK_DOWN]){   guy.rot -= 2;}move();//here is the implementation of move()void move(){   guy.y += sin(DEG_TO_RAD(guy.rot)) * guy.speed;   guy.x += cos(DEG_TO_RAD(guy.rot)) * guy.speed;}
------------------------------------------------------- A headache, ancillary; an hourglass auxiliary."something witty, blah, blah, blah" --That One Witty Guy (remember? that one dude?)(author of DustBot)
Advertisement
No its not working. 0° should move me up. 180° should move me down and 45° should move me 1 up on the x and 1 up on the y.

[Edit] didn't see your post. I didn't post the angle changing part because it works. Its the part where I move at the angle that doesnt.
--------------------C++ Home - Check it out!Lol... - Amazing video
Ah, I see. The problem is that the unit circle travels in a counter clock wise direction while you want it to work the other way . . . the other problem is that you want 0 to move you up. This should be an easy solution. Try adding 90 to the current angle, and negate the current angle as well, so the code for up might look like:

guy.y += sin(DEG_TO_RAD(-guy.rot+90));
guy.x += cos(DEG_TO_RAD(-guy.rot+90));

tell me if it works or not.
Nope. I can't even see a pattern this time
--------------------C++ Home - Check it out!Lol... - Amazing video
well, then . . . i'm not sure what to say. I thought for sure the last bit would work. Hmmm . . . because if you think about it, adding 90 to the angle will make sin(0+90) = 1 therefore you move forward, and sin(90-90) is 0 while cos(90-90) is 1, so you move right, and so on and so forth.

Edit: Purhaps something is wrong elsewhere?
Some combination of positive and negative sin and cos should be working for you. How are your world axes oriented (i.e. y up and x right)? Which direction (clockwise or counterclockwise) is 'positive' rotation for you? Given this information, we should be able to figure out your problem.
Ok, I'm using OpenGL with ortho turned on so that the top left of the screen is 0, 0. Rotating CW will give me a positive rotation while rotating CCW will give me a negative rotation.
   0270  45  180
y is up and x is right. Heres my source to date. It draws the rotation properly but I won't move the right direction.

void Update(){	if(keys[VK_UP] || keys['W'])	{		guy.y += cos(DEG_TO_RAD(-guy.rot + 90));		guy.x += sin(DEG_TO_RAD(-guy.rot + 90));	}	else if(keys[VK_DOWN] || keys['S'])	{		guy.y -= cos(DEG_TO_RAD(-guy.rot + 90));		guy.x -= sin(DEG_TO_RAD(-guy.rot + 90));	}	if(keys[VK_LEFT] || keys['A'])	{		guy.rot--;		if(guy.rot < 0)			guy.rot += 360.0f;	}	else if(keys[VK_RIGHT] || keys['D'])	{		guy.rot++;		if(guy.rot > 359)			guy.rot -= 360.0f;	}}
--------------------C++ Home - Check it out!Lol... - Amazing video
Just thought I'd mention I got it working. I changed DEG_TO_RAD to #define DEG_TO_RAD(x) (((x) * 3.14159) / 180)

Then I took te - off of guy.rot and it worked! Thanks.
--------------------C++ Home - Check it out!Lol... - Amazing video

This topic is closed to new replies.

Advertisement