CollisionRay and hide model

Hello!
i’m making a FPS game (i would like). I attach a collision sphere to cam to check collisions with walls and floors. I attach a CollisionRay to cam to check collisions when i press mouse1 button. The follow function is called by taskManager

    def playerFire(self, task):
        if (self.keys['fire']):
            mpos = base.mouseWatcherNode.getMouse()
            self.pickerRay.setFromLens(self.cam.node(), mpos.getX(), mpos.getY())
            self.fireTrav.traverse(self.render)
            if self.handler.getNumEntries() > 0:
                # This is so we get the closest object
                self.handler.sortEntries()
                print self.handler.getEntries()
                pickedObj = self.handler.getEntry(0).getIntoNodePath()
                print self.handler.getEntry(0)
                pickedObj.hide()
        else:
            self.lastFire += task.getDt()
        return task.cont

but the first entry is the collision sphere of the camera.
i try to get 1 or 2 entry instead the 0, but the object that i have clicked, doesn’t hide.
the follow method is the init method

 def __init__(self): 
        ShowBase.__init__(self)
        base.disableMouse()
        
        self.cam.setPos(0, 0, 0) 
        
        self.cTrav = CollisionTraverser() 
        pusher = CollisionHandlerPusher()
        pusher.setHorizontal(False)
        
        self.fireTrav = CollisionTraverser()
        self.handler = CollisionHandlerQueue()
        pickerNode = CollisionNode('mouseRay')
        pickerNP = self.cam.attachNewNode(pickerNode)
        pickerNP.show()
        self.pickerRay = CollisionRay()
        pickerNode.addSolid(self.pickerRay)
        self.fireTrav.addCollider(pickerNP, self.handler)
        self.fireTrav.showCollisions(self.render)
        
        fromObj = self.cam.attachNewNode(CollisionNode("cam")) 
        fromObj.node().addSolid(CollisionSphere(0, 0, 0, 1.25)) 
        fromObj.show() 
        pusher.addCollider(fromObj, self.cam) 
        self.cTrav.addCollider(fromObj, pusher) 
        
        wall = self.loader.loadModel("tunnel") 
        wall.reparentTo(self.render) 
        wall.setPos(-0.5, -0.5, -0.5)
        wall.setScale(5, 5, 5)
        
        self.ball = self.loader.loadModel("ball")
        self.ball.reparentTo(self.render)
        self.ball.setPos(0, 0, 0)

why?

thanks for all!!! :astonished:

I have resolved using a BitMask applied to collisionRay. But i don’t understand how BitMask works. For example, why does it work now? BitMask is needed to capture a collision between two masked object (they must have same make). But i don’t set a BitMask to the ball. Then, why is the collision caputured?

There is a default BitMask. I don’t remember what it’s set to exactly, but I suppose it’s a “collide with everything” kind of thing.

a… oki!!
thank you!!!
It resolves all issue!! :smiley: