# First person shooter camera movement

I am making an FPS in XNA. I cannot seem to make a FPS camera that I can move Forward, Back, Side to Side using the keyboard. How do I do that?

• What have you tried so far? Google has tons of information, especially on such a simple subject. Look it up on the internet, you will find it. Then, if you have a specific problem, you can ask your question here. This question is way to broad for this site. Aug 13, 2013 at 13:46
• Sorry about that.... Obviously, I'm kinda new to the site Aug 13, 2013 at 17:34

here is some basic code that will work for you.

//class scope fields
Vector3 camPosition, camTarget;

//in the camera Update method
Matrix ViewToWorld = Matrix.Invert(view);

if(/* W key is down */)
{
camPositon += viewToWorld.Forward * speed;//speed should include a factor of frame delta time
camTarget += viewToWorld.Forward * speed;
}

// same code as above for S key but use viewToWorld.Backward instead

if(/* D key is down */)
{
camPositon += viewToWorld.Right * speed;
camTarget += viewToWorld.Right * speed;
}

//same code as above for A key but use viewToWorld.Left instead

view = Matrix.CreateLookAt(camPosition, camTarget, Vector3.Up);

• Quick Question. When you say Matrix ViewToWorld = Matrix.Invert(view); is it supposed to be viewToWorld? Aug 13, 2013 at 15:57
• read again your question... without dude... yes.. ViewToWorld is supposed to be ViewToWorld... the view matrix converts from world to view... if you invert it... you get a matrix that converts from view to world... ;)
– Blau
Aug 13, 2013 at 16:06
• I don't think you understand :P What I'm trying to ask is was there a typo and is ViewToWorld supposed to be viewToWorld (v is lowercased) Aug 13, 2013 at 16:13
• Yes, that was a typo. Sorry. They should all be same case Aug 13, 2013 at 19:26