Skip to main content
gamedev.net
🔒 Locked

moving problem

Started by hello_there 10 replies 800+ views
Original Post
hello_there
hello_there
i want the player to move forward at the current angle and i could think of how to do it. i want to know how would i move it up the right amout on the y and the x i have no idea how to do this.
____________How could hell be worse?
JuNC
JuNC
x'' = x + cos( angle ) * speed
y'' = y + sin( angle ) * speed

SporadicFire
SporadicFire
note that in JUNC''s posting angle MUST be in radians...if angle is in degrees:

x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed

(dont forget to define PI)
uNiQue0815
uNiQue0815
do you save your camera as position & angles
or a matrix ?
Omaha
Omaha
This should be in the math section.
IndirectX
IndirectX
My fps-style camera has a vector center, "head" direction basis (three orthogonal vectors) and three Euler angles representing orientation relative to "head" direction (strafe vs look). I used quaternion for orientation at some point, but Euler angles are easier to constrain, since in FPS you don''t really have 6 DOF.
---visit #directxdev on afternet <- not just for directx, despite the name
hello_there
hello_there
i save it as position and angle also this equation doesn''t work properly

x'' = x + cos( angle *PI/180) * speed
y'' = y + sin( angle *PI/180) * speed

if i hold down up and spin the camera it just goes up and down the y axis.

____________How could hell be worse?
IndirectX
IndirectX
What are you expecting? Those equations will translate camera, not rotate it.
---visit #directxdev on afternet <- not just for directx, despite the name
hello_there
hello_there
but i want to translate camera?
____________How could hell be worse?
Mihail121
Mihail121
Go check the camera lessons at http://www.gametutorials.com.You can use them in your engine.They are the coolest and the fullest



The pain is coming...this sommer!!!
zelda6486
zelda6486
//declare these variables

float rot=0; //angle
float px=0.0; //player x
float pz=0.0; //player z
double R=3.141593/180.0f; //radians to degrees

//before drawing each frame, do this:
glLoadIdentity();
glRotatef(rot,0.0f,1.0f,0.0f);
glTranslatef(px,-5.0f,pz);

//when checking for input
if(key[VK_LEFT]==true) {rot=rot-10;
if(rot<0) rot=rot+360;}

if(key[VK_RIGHT]==true) {rot=rot+10;
if(rot>3600) rot=rot-360;}

if(key[VK_UP]==true) {
px=px-sin(rot*R)*1.0); //1.0=speed
pz=pz+cos(rot*R)*1.0);
if(key[VK_DOWN]==true) {
px=px-sin(rot*R)*-1.0); //-1.0=speed
pz=pz+cos(rot*R)*-1.0);

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.