Beispiel #1
0
def setup_ray(node, traverser, bitmask, point_a=(0, 0, 1), point_b=(0, 0, 0)):
    ray = CollisionSegment(point_a, point_b)
    col = CollisionNode(node.getName() + "-ray")
    col.add_solid(ray)
    col.set_from_collide_mask(bitmask)
    col.set_into_collide_mask(CollideMask.all_off())
    col_node = node.attach_new_node(col)
    handler = CollisionHandlerQueue()
    traverser.add_collider(col_node, handler)
    return {"collider": col, "ray": ray, "handler": handler, "node": col_node}
Beispiel #2
0
 def ray(self, name, bitmask, point_a=(0, 0, 1), point_b=(0, 0, 0)):
     shape = CollisionSegment(point_a, point_b)
     col = CollisionNode(self.node.getName() + "-ray-" + name)
     col.add_solid(shape)
     col.set_from_collide_mask(bitmask)
     col.set_into_collide_mask(CollideMask.all_off())
     col_node = self.node.attach_new_node(col)
     handler = CollisionHandlerQueue()
     self.traverser.add_collider(col_node, handler)
     return {
         "collider": col,
         "shape": shape,
         "handler": handler,
         "node": col_node
     }
Beispiel #3
0
    def __init__(self, world):
        self.world = world
        self.root = self.world.root.attach_new_node("player")
        self.root_target = self.world.root.attach_new_node("player_target")
        self.pivot = self.root.attach_new_node("player_pivot")
        base.camera.reparent_to(self.pivot)
        base.camera.set_z(1.7)
        base.cam.node().get_lens().set_fov(90)
        self.traverser = CollisionTraverser()
        self.ray = setup_ray(
            self.pivot,
            self.traverser,
            self.world.mask,
            # ray ends well below feet to register downward slopes
            (0, 0, 1),
            (0, 0, -1))
        self.xyh_inertia = Vec3(0, 0, 0)
        h_acc = ConfigVariableDouble('mouse-accelleration', 0.1).get_value()
        self.xyh_acceleration = Vec3(0.8, 0.8, h_acc)
        self.friction = 0.15
        self.torque = 0.5
        self.last_up = Vec3(0, 0, 1)

        # Collider for portals
        csphere = CollisionSphere(0, 0, 1.25, 1.5)
        cnode = CollisionNode('player')
        cnode.add_solid(csphere)
        cnode.set_from_collide_mask(0x2)
        cnode.set_into_collide_mask(CollideMask.all_off())
        self.collider = self.root.attach_new_node(cnode)
        self.event_handler = CollisionHandlerEvent()
        self.event_handler.add_in_pattern('into-%in')
        self.traverser.add_collider(self.collider, self.event_handler)
        self.collider.show()
        self.teleported = False

        base.input.set_mouse_relativity(True)