# Confused with matrices in XNA

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

## Recommended Posts

I have read several detailed tutorials about matrices, but I never can get them to work right. In my game, the player's position on the map is a Vector3 at the player's head . This vector is altered by keyboard input, so for example if Keys.W is pressed then position.Z+=speed*time since last frame. Then I create a new view matrix each frame with the new player position. Is this a good way to do a first person camera? It never seems to work right for me. Even without doing rotations, it rotates all over the place and goes out of view.

##### Share on other sites
I think we would need more code from you to be able to tell what are you doing wrong.

In theory, what you said should work, so if it doesn't then you have some error somewhere. But of course it's only a very simple implementation, I think you are aware of the fact that you are not moving the player "forward" (in the direction he's facing) but always on the Z axis.

We really need more info from you, not just an example of what the W key is doing.

##### Share on other sites
I've run into this kind of problem before, and it always stemmed from my camera/player's movement update function. If you have a method that updates position or rotation every frame based on another vector (modified by player input), make sure you zero out the referenced vector after you create the transformation matrix.

That's just a blind guess though, so like Tom mentioned, some code would be helpful ;)

##### Share on other sites
I don't know whether your problem is related to the order of matrix operations you're doing, because matrix multiplication is not commutative. Also I don't quite understand what you mean when you say the first-person camera goes "out of view" from itself. But as a rule of thumb, for most cases you would need to follow the S-R-T mnemonic, that is, Scale, Rotate, then Translate in that order. This would help keep your camera from rotating around a point that's different from its own location. Edited by CC Ricers

1. 1
2. 2
Rutin
21
3. 3
A4L
15
4. 4
5. 5

• 13
• 26
• 10
• 11
• 44
• ### Forum Statistics

• Total Topics
633741
• Total Posts
3013624
×