# strafe movement

This topic is 5147 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi all, I have a working first person camera, I have implemented strafing left and right. I did this by adding the right vector of the view matrix to the cameras position vector, such as : D3DXVECTOR m_CamPos; m_CamPos += D3DXVECTOR3(m_Right.x, 0, m_Right.z) * unit; Now, this code came out of a book, I kind of get it, obviously to move left or right, we need the right vector which is the x-axis vector in the view matrix. What I don't get is, why do we have to add the value of m_Right.z to the camera, why can't I just have: m_CamPos += m_Right.x * unit; or even m_CamPos += unit; Sorry to be slow on this, hope someone can explain. Kindest regards, Steve

##### Share on other sites
Imagine when the player is looking down say the positive X-axis. Your camera's front (or view) vector would then be (1, 0, 0) and your camera's right vector would be (0, 0, -1). As you can see adding only right.x would result in nothing at all.

##### Share on other sites
Thanks,

But what is cameras front vector ? Sorry to be thick, but still not sure on this !

Is front vector the look vector ?

##### Share on other sites
front vector is the look vector (or maybe projected only to one plane--so you can look up, but when u face front its not upwards too).

The reason u dont add x++ to strafe right is:
lets say you are facing in the z direction, now you turn left 90 degrees, now ur facing in the x direction and if you added to x to strafe you'd be going backwards.
It is basically an object-space (front, side, position system) to world-space transformation that you're overlooking. In the world your vectors look very different than relative to yourself (object-space), where front is always front (positive Z), left is always left (negative X) and so on.
Lets say you put yourself upside down in a yoga position (heh), then your vectors get all jumbled up in the world, but relative to you up is still positive Y, so the sky for you is the ceiling and vice versa.

##### Share on other sites
<quote>
or even m_CamPos += unit;</quote>

You might not want that is you want variably-sized strafes. You could do that if you move a certain distance each keypress or something.

Regards,
Steve

1. 1
Rutin
28
2. 2
3. 3
4. 4
5. 5

• 13
• 11
• 10
• 13
• 20
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009424
• ### Who's Online (See full list)

There are no registered users currently online

×