~fireclawthefox/panda3dcodecollection/trunk

« back to all changes in this revision

Viewing changes to character/extended Char controller/CameraThirdPerson.py

  • Committer: Fireclaw the Fox
  • Date: 2017-05-27 17:41:04 UTC
  • Revision ID: fireclawthefox@gmail.com-20170527174104-ku862wzxjqr2n9s4
Made enter animation duration configurable
Made shadow offset configurable
Enable button controlling of the first person cam
Make camera position transition smooth with an interval in third person mode
Some fixes and enhancements for gamepad usage
Fixes regarding python3 usage
Add show and hide functions to the PlayerController
Extended collision and position checks for the ledge grab plugin
Added instructions to the OSD

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
        self.last_platform_position_cam = None
29
29
        self.last_platform_rotation_cam = None
30
30
 
 
31
        self.ival_move_cam = None
 
32
 
31
33
        self.cam_ray = "camera_check_ray"
32
34
        self.parent.registerRayCheck(self.cam_ray, (0,0,0), (0,0,1), render)
33
35
 
67
69
        the defined model and will correct the position if the cam is to close
68
70
        or to far away"""
69
71
 
 
72
        if self.ival_move_cam is not None and self.ival_move_cam.isPlaying():
 
73
            camera.lookAt(self.cam_floater)
 
74
            # move the mouse to the center
 
75
            base.win.movePointer(0, self.parent.win_width_half, self.parent.win_height_half)
 
76
            return task.cont
 
77
 
70
78
        if self.parent.useKeyboard:
71
79
            cam_left = self.parent.isDown(self.parent.key_camera_left)
72
80
            cam_right = self.parent.isDown(self.parent.key_camera_right)
73
81
            cam_up = self.parent.isDown(self.parent.key_camera_up)
74
82
            cam_down = self.parent.isDown(self.parent.key_camera_down)
75
83
            cam_center = self.parent.isDown(self.parent.key_center_camera)
76
 
        elif self.parent.useGamepad:
77
 
            cam_left = self.parent.gamepad.getCamButton("arrow_left")
78
 
            cam_right = self.parent.gamepad.getCamButton("arrow_right")
79
 
            cam_up = self.parent.gamepad.getCamButton("arrow_up")
80
 
            cam_down = self.parent.gamepad.getCamButton("arrow_down")
81
 
            cam_center = self.parent.gamepad.getCenterCamState()
 
84
        if self.parent.useGamepad and self.parent.gamepad is not None:
 
85
            cam_left = cam_left or self.parent.gamepad.getCamButton("arrow_left")
 
86
            cam_right = cam_right or self.parent.gamepad.getCamButton("arrow_right")
 
87
            cam_up = cam_up or self.parent.gamepad.getCamButton("arrow_up")
 
88
            cam_down = cam_down or self.parent.gamepad.getCamButton("arrow_down")
 
89
            cam_center = cam_center or self.parent.gamepad.getCenterCamState()
 
90
            cam_rotation = self.parent.gamepad.getRotationVec()
82
91
 
83
92
        # Camera Movement Updates
84
93
        camvec = self.cam_floater.getPos(render) - camera.getPos(render)
220
229
                pos.setY(pos.getY() + wall_normal.getY()/2.0)
221
230
            if pos is not None:
222
231
                had_ray_collision = True
223
 
                camera.setPos(pos)
 
232
                if self.ival_move_cam is None or self.ival_move_cam.isStopped():
 
233
                    offset_z = pos.getZ() - self.cam_floater.getZ(render)
 
234
                    if offsetZ < self.parent.min_cam_height_distance:
 
235
                        # the position is to low, so move it up
 
236
                        pos.setZ(self.cam_floater.getZ(render) + self.parent.min_cam_height_distance)
 
237
                    elif offsetZ > self.parent.max_cam_height_distance:
 
238
                        # the position is to high, so move it down
 
239
                        pos.setZ(self.cam_floater.getZ(render) + self.parent.max_cam_height_distance)
 
240
 
 
241
                    dist = pos - self.cam_floater.getPos()
 
242
 
 
243
                    duration = dist.length() * self.parent.cam_reposition_duration
 
244
 
 
245
                    self.ival_move_cam = camera.posInterval(duration, pos)
 
246
                    self.ival_move_cam.start()
 
247
                #camera.setPos(pos)
224
248
 
225
249
        # If player is to close move the camera backwards
226
250
        if camdist < self.parent.min_cam_distance: