Switching Perspective

Hey, all. My goal is to switch a single camera from a 1st person position inside the character model to a place outside the character in 3rd person.

While in 1st person, the camera controls should behave as would be expected in any FPS, and in third person the camera will rotate about the player while looking at the player. This is what I have so far:

heading = 0
pitch = 0
pov = True


def CameraSwap(self):
   global pov
   if (pov == True):
      pov = False
   if (pov == False):
      pov = True
      base.camera.setPos(self.player, 0,0,0)

def updatePlayer(self, task):
   elapsed = globalClock.getDt()
   global heading
   global pitch
   global pov

   if pov:

      if base.mouseWatcherNode.hasMouse():
         md = base.win.getPointer(0)
         x = md.getX()
         y = md.getY()
         if base.win.movePointer(0, base.win.getXSize()/2, base.win.getYSize()/2):
            base.camera.setP((base.camera.getP() - (y-base.win.getYSize()/2)*self.MouseSen) % 360)
         self.player.setH((self.player.getH() - (x-base.win.getXSize()/2)*self.MouseSen) % 360)

   if not pov:
      self.accept('wheel_up', lambda :base.camera.setY(base.camera.getY()+100 * globalClock.getDt()))
      self.accept('wheel_down', lambda : base.camera.setY(base.camera.getY()-100 * globalClock.getDt()))

      md = base.win.getPointer(0)

      a = md.getX()
      s = md.getY()

      if base.win.movePointer(0, 300, 300):
         heading = heading - (a - 300) * 0.5
         pitch = pitch - (s - 300) * 0.5

         base.camera.setHpr(heading, pitch,0)

return task.cont

When I launch the game, first person works as intended.

Once I switch to third person, the camera is outside the body as intended, except the camera isn’t looking at my player node (its rotating around the camera’s axis and not orbiting the player).

And then when I switch back to 1st person, the camera will orbit the player like it was supposed to in 3rd person, and it does not go back to (0,0,0) inside the player model.

Switching back out after that, the 3rd person camera is out of the body, but again, it’s not looking at the player but is rotating like an FPS camera.

What am I getting wrong?

Having the camera return to the proper places inside the player model was achieved by switching base.cam for base.camera, so that’s one problem down.

I still can’t get the 3rd person camera to properly look at the player, though.

[getting closer objects)

getting closer objects]

I don’t think that addresses why base.camera.lookAt(self.player) isn’t working in my script. Not at all.

But your post does address a problem I might have in the future, so thanks.

Problem is unresolved.

Problem resolved by

base.camera.setHpr(heading, pitch,0) 


self.player.setHpr(heading, pitch,0) 

lol thanks guys.