# Thread: How to move forward - again

1. ## How to move forward - again

glTranslatef(x,y,z);
glRotatef(ax,1,0,0);
glRotatef(ay,0,1,0);
glRotatef(az,0,0,1);

How to calculate the correct x,y,z to make me move forward,backward,right and left?

2. ## Re: How to move forward - again

Depends on the size of your world and unit that you are using.

let's use Z as our forward axis.

if( Object.forward == TRUE )z++; // The number we give to Z is based on our world size.
You may want to play around to see what value gives you the smoothes movement.
The same goes with turning right of left, start with 1 and go from there.

What each variable does, at least in a first person shooter...

Z axis is our forward and backward movement.
X axis would be strafe right of left(side step).
Y axis is our up/down movement.

ax look to the right or left and direction of travel on the x plane.
ay is look up/down

Originally posted by MyNameIsJohnny:
glTranslatef(x,y,z);
glRotatef(ax,1,0,0);
glRotatef(ay,0,1,0);
glRotatef(az,0,0,1);

How to calculate the correct x,y,z to make me move forward,backward,right and left?

3. ## Re: How to move forward - again

But the question is, when I rotate the camera, Z its not my front anymore...

4. ## Re: How to move forward - again

use sin and cos, i'd give more info but I have too much of a headache to think

5. ## Re: How to move forward - again

You have two planes.

One is your worlds XYZ plane.

Z is always your front, thought your not facing the worlds Z. Just like if you are walking north or south, ether direction you are still moving forward.

Remember in openGL your camara can not move, what happens is you move your world around it.

Originally posted by MyNameIsJohnny:
But the question is, when I rotate the camera, Z its not my front anymore...

6. ## Re: How to move forward - again

nexusone.

I undestand what your are saying. But please, I know that you understood my problem. Its just a liltle trigonometry formula... help me

7. ## Re: How to move forward - again

Maybe later I will feel like finding some code to post... kind of late here.

but it has to do with sin/cos to find movement along a angle vector.

Originally posted by MyNameIsJohnny:
nexusone.

I undestand what your are saying. But please, I know that you understood my problem. Its just a liltle trigonometry formula... help me

8. ## Re: How to move forward - again

Back to the subject of movement....

xa = cos(angle); Where angle is direction of movement.
ya = sin(angle);

player.x = player.x + xa * rate;rate is => 1, the higher the number the faster the movement.
player.y = player.x + ya * rate;

// In your drawing routine something like this.

glTranslatef(player.x, player.y, 0); move player the correct position.
glRotatef(angle, 0,0,1); rotate player to correct direction.
draw_player.

note this is sample code not everything needed is presented here.

player.x and player.y keep track of player current location.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•