Beispiel #1
0
    def server_created_object(self, tag, height, radius):
        # This shape is used for collision detection, preventing the player falling through the ground for
        # example.
        shape = BulletCapsuleShape(radius, height - 2 * radius, ZUp)

        # A character controller is a physical body which responds instantly to keyboard controls.  (Bodies
        # which respond to forces are difficult to control in a satisfactory way using typical video game
        # controls.  Players expect them to move instantly when a button is pressed, but physics dictates that
        # they should take a short time to accelerate.)
        node = BulletCharacterControllerNode(shape, 0.4, tag)
        node_path = self.render.attachNewNode(node)
        Thing.add(tag, node, node_path)
        self.world.attachCharacter(node)

        # Does this object represent the player who is using this client?
        if tag == self.__player_tag:
            # If yes, attach the camera to the object, so the player's view follows the object.
            self.camera.reparentTo(node_path)
        else:
            # If no, create a new Actor to represent the player or NPC.
            humanoid = Actor("player.bam")
            humanoid.setH(180)
            humanoid.reparentTo(node_path)

            # Scale the Actor so it is the same height as the bounding volume requested by the server.
            point1 = Point3()
            point2 = Point3()
            humanoid.calcTightBounds(point1, point2)
            humanoid.setScale(height / (point2.z - point1.z))

            # If the 3D model has the origin point at floor level, we need to move it down by half the height
            # of the bounding volume.  Otherwise it will hang in mid air, with its feet in the middle of the
            # bounding volume.
            humanoid.setZ(-height / 2)
Beispiel #2
0
    def server_created_object(self, tag, height, radius):
        # This shape is used for collision detection, preventing the player falling through the ground for
        # example.
        shape = BulletCapsuleShape(radius, height - 2 * radius, ZUp)

        # A character controller is a physical body which responds instantly to keyboard controls.  (Bodies
        # which respond to forces are difficult to control in a satisfactory way using typical video game
        # controls.  Players expect them to move instantly when a button is pressed, but physics dictates that
        # they should take a short time to accelerate.)
        node = BulletCharacterControllerNode(shape, 0.4, tag)
        node_path = self.render.attachNewNode(node)
        Thing.add(tag, node, node_path)
        self.world.attachCharacter(node)

        # Does this object represent the player who is using this client?
        if tag == self.__player_tag:
            # If yes, attach the camera to the object, so the player's view follows the object.
            self.camera.reparentTo(node_path)
        else:
            # If no, create a new Actor to represent the player or NPC.
            humanoid = Actor("player.bam")
            humanoid.setH(180)
            humanoid.reparentTo(node_path)

            # Scale the Actor so it is the same height as the bounding volume requested by the server.
            point1 = Point3()
            point2 = Point3()
            humanoid.calcTightBounds(point1, point2)
            humanoid.setScale(height / (point2.z - point1.z))

            # If the 3D model has the origin point at floor level, we need to move it down by half the height
            # of the bounding volume.  Otherwise it will hang in mid air, with its feet in the middle of the
            # bounding volume.
            humanoid.setZ(-height / 2)