Jump to content
  • Advertisement
Sign in to follow this  
steg

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.

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
Advertisement
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
Thanks,

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

Is front vector the look vector ?

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!