Sign in to follow this  

strafe movement

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this