collision handler

i want the sphere to disappear when the (keyboard-controlled) hero collides into it.But here our hero glides through it smoothly . plz help

self.cTrav = CollisionTraverser()

        self.heroGroundRay = CollisionRay()
        self.heroGroundRay.setOrigin(0,0,1000)
        self.heroGroundRay.setDirection(0,0,-1)
        self.heroGroundCol = CollisionNode('heroRay')
        self.heroGroundCol.addSolid(self.heroGroundRay)
        self.heroGroundCol.setFromCollideMask(BitMask32.bit(0))
        self.heroGroundCol.setIntoCollideMask(BitMask32.allOff())
        self.heroGroundColNp = self.hero.attachNewNode(self.heroGroundCol)
        self.heroGroundHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.heroGroundColNp, self.heroGroundHandler)

self.model2CollisionSolid = CollisionSphere(12, 0, 5, 1)
        
        self.model2CollisionCol = CollisionNode('model2Sphere')
        self.model2CollisionCol.addSolid(self.model2CollisionSolid)
        self.model2CollisionCol.setFromCollideMask(BitMask32.bit(0))
        self.model2CollisionCol.setIntoCollideMask(BitMask32.allOn())
        self.model2CollisionColNp = self.hero.attachNewNode(self.model2CollisionCol)
        self.model2CollisionColHandler = CollisionHandlerQueue()
        self.cTrav.addCollider(self.model2CollisionColNp, self.model2CollisionColHandler)

#the following lines are in a task
entries = []
        for i in range(self.model2CollisionColHandler.getNumEntries()):
            entry = self.model2CollisionColHandler.getEntry(i)
            entries.append(entry)
        entries.sort(lambda x,y: cmp(y.getSurfacePoint(render).getZ(),
                                     x.getSurfacePoint(render).getZ()))
        if (len(entries)>0) and (entries[0].getIntoNodePath()== self.heroGroundColNp):
            self.model2.hide()

I can’t solve your problem, but I can give some advice how to solve it yourself.

First, try to answer whether a collision is being detected at all. One easy way to do this is to add a call to self.cTrav.showCollisions(render), which will make collision solids light up yellow when collisions are tested, and white when collisions are detected. If you see your sphere lighting up white, then the collision is being detected, and there’s something wrong with the way you’re responding to it (for instance in the entries loop). If you don’t see your sphere lighting up, then the collision isn’t being detected and there’s something wrong in the way you’ve set up the collision handler (maybe you’re not calling traverse() or something).

David