# Little Help Needed with an FPS Camera (C#)

## Recommended Posts

Spawned218    122
Hey guys, or girls (if you happen to be one :] ) Can anyone spell out exactly how the formulas should be for calculating cameraPosition and cameraLookAt in C# (using XNA 2.0) while dealing with a First Person Shooter style camera. What i'm looking for in regards position is how to get the values added to the Vector3's X and Z values (Y is up) in order to allow movement. And as far as the lookAt is concerned, how to get smooth movement AND start off actually looking at the test model at 0,0,0. I have to go searching with the camera in order to find the dang model! Any and all help is appreciated. Thanks people! Oh, one more thing... Is there any way to draw a 3D line between two Vector3 points? Like showing up a bullet's vector line between target and gun barrel? Thanks again M@t.

##### Share on other sites
Nypyren    12061
For line drawing, you can use something like:

device.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, verts, 0, verts.Length, indices, 0, points.Length-1);

Of course you'll have to create the "VertexPositionColor[] verts;" and "short[] indices;" arrays and call this between a typical Effect.Begin() / Effect.End() pair.

For manual camera control, try experimenting with a Matrix's Up, Right, Forward and Translation properties.