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 self.accept("k",self.CameraSwap) def CameraSwap(self): global pov if (pov == True): pov = False base.camera.setPos(0,0,0) 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: self.ignore('wheel_up') self.ignore('wheel_down') 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: base.camera.lookAt(self.player) 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?