# FPS camera

Hi!!!
i make a fps camera in a 3d world but when i’m on below, my camera rotate to left on my moving mouse on right and vice versa.
I use this code to control the camera

``````md = base.win.getPointer(0)
x = md.getX()
y = md.getY()
rotVel = 0.4
if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
self.cam.setH(self.cam.getH() -  (x - base.win.getXSize()/2)*rotVel)
self.cam.setP(self.cam.getP() - (y - base.win.getYSize()/2)*rotVel)

vel = 200
if (self.keys['forward']):
backward = self.cam.getNetTransform().getMat().getRow3(1)
backward.normalize()
if (self.keys['back']):
backward = self.cam.getNetTransform().getMat().getRow3(1)
backward.normalize()

if (self.keys['right']):
backward = self.cam.getNetTransform().getMat().getRow3(0)
backward.normalize()
if (self.keys['left']):
backward = self.cam.getNetTransform().getMat().getRow3(0)
backward.normalize()

if(self.keys['up']):
backward = self.cam.getNetTransform().getMat().getRow3(2)
backward.normalize()
if(self.keys['down']):
backward = self.cam.getNetTransform().getMat().getRow3(2)
backward.normalize()
``````

why does this appening ?

Because the H, P, R rotations are all defined to be counterclockwise, by convention. This means that +H rotates the camera to the left.

David

i don’t understand what do you tell me!

My code works correctly until i’m on below…

Just change the first - to a + in your setH call.

the - operation is right.
I’m going to explain better my issue:
When i turn of 180 degrees on x axis, the left’s movement of the mouse generates a right’s movement of the camera. It appends because i’m upside down. To avoid this behavior, am i obliged to add a check or does a workaround exist?

Sounds like you want to adjust the camera relative to its current orientation. You can set the H relative to the camera itself: self.cam.setH(self.cam, newH).

David

Wouldn’t it be better to just prevent the camera from going up side down? In most FPP games that doesn’t happen, so you should just code in a limiter for the camera’s pitch.

Ever played “Prey” mate?

Heh, good point. Still, that’s a rather unusual case . Same to Alien vs. Predator.

To use self.cam.setH(self.cam, newH) method, I write this:

``self.cam.setH(self.cam.getH(), -  (x - base.win.getXSize()/2)*rotVel))``

but no work correctly

Thanks for all

That’s not what I said. Try this:

``self.cam.setH(self.cam, -  (x - base.win.getXSize()/2)*rotVel))``

David