Collisions: Collision solids hit everything regardless of bitmask

Hi! I’m trying to get started with making a game using Panda3D, and I’m working creating a test game to get the basics of Panda3D down. I’m pretty decent with python, but completely new to Panda3D.

Bottom Line: my collision nodes are colliding with everything, regardless of their bitmask.

Here’s the code:

        self.wallbitmask = BitMask32.bit(11)
        self.floorbitmask = BitMask32.bit(1)
    
        playerfloordetector = CollisionRay()
        playerfloordetector.setOrigin(0, 0, 2)
        playerfloordetector.setDirection(0, 0, -1)
        floor_collisions = CollisionNode('floor_detection')
        floor_collisions.addSolid(playerfloordetector)
        floor_collisions.setFromCollideMask(self.floorbitmask)
        floor_collisions.setIntoCollideMask(BitMask32.allOff())
        floor_collisions_np = self.player.attachNewNode(floor_collisions)
        self.floordetectionHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(floor_collisions_np, self.floordetectionHandler)

        wallcollider = CollisionNode('wall_detection')
        wallcollider.add_solid(CollisionBox((0, 0, 0.7), 0.5, 0.5, 0.5))
        wallcollider.set_from_collide_mask(self.wallbitmask)
        wallcollider.set_into_collide_mask(BitMask32.allOff())
        wall_collision_np = self.player.attachNewNode(wallcollider)
        wallpusher = CollisionHandlerPusher()
        wallpusher.add_collider(wall_collision_np, self.player)
        self.cTrav.add_collider(wall_collision_np, wallpusher)

        floor_collisions_np.show()
        wall_collision_np.show()
        self.cTrav.show_collisions(render)

        floor = loader.loadModel(terrain_location)
        floor.node().set_into_collide_mask(self.floorbitmask)
        floor.reparentTo(render)
        floor.hide()

        walls = loader.loadModel(wall_location)
        walls.node().set_into_collide_mask(self.wallbitmask)
        walls.reparentTo(render)
        walls.hide()

        taskMgr.add(self.collision_task, "bumpdetection")

The task just prints out what the collision ray is hitting. The floor and walls models are OBJ’s I created in blender, then converted to egg, then added the line: terrain {polyset descend}

The idea behind it is that I create a floor detecting ray to detect the floor line, then move the player’s Z to that point so he can walk up ramps and such. For walls, I just wanted the player to slide along them, so I used the CollisionHandlerPusher instead. What I’ve noticed is that if I comment out all the collisionray/floor detection stuff, the collisionhandlerpusher still keeps the player from walking through the ramps, even though the ramped floor uses the floorbitmask. Furthermore, if I point the ray straight ahead (+Y), it lists that it’s hitting the walls even though the walls use the wallbitmask. Why are the bitmasks not filtering out collision solids? Is there something I’m missing in setting up the collision nodes or collision handler? Is this even the best way to manage collisions? Thank you for any help you can provide!

I figured out the problem after some trial and error. In case anyone comes across a similar issue, here’s what I did:

First, in the .egg file, there’s a line that looks like:

<Group> floor {
  <Collide> floor {polyset descend}
  <Polygon> {

The collide and group names need to be the same. Before, I assumed the Collide name was arbitrary.
Second, you need to load the .egg like so:

        floor = loader.loadModel(terrain_location)
        floor_collision = floor.find("**/floor")
        floor_collision.node().set_into_collide_mask(self.floorbitmask)
        floor_collision.reparentTo(render)
        floor_collision.hide()

After you run the loader.loadModel command, you still need to do the “find” command. After that, the bitmasks worked properly.