Shooting a "gun"

Hi, I been trying to figure out how to shoot a gun but can’t seem to get it to work or I dont understand a little bit of the code.

I know you need to use “clicking on 3d objects” by “shooting” a ray and test to see what it hits, but for some reason I don’t get what i’m trying to hit back to me. Actully I dont know if i’m doing the code right at all either.

    def Collisions(self):
      base.cTrav = CollisionTraverser()
      base.pusher = CollisionHandlerPusher()
      base.pusher.setHorizontal(False)
      base.handler = CollisionHandlerQueue()

      self.pickerNode=CollisionNode('mouseRay')
      self.pickerNP=base.camera.attachNewNode(self.pickerNode)
      self.pickerNode.setFromCollideMask(BitMask32.bit(0))
      self.pickerNode.setIntoCollideMask(BitMask32.allOff())
      self.pickerRay=CollisionRay()
      self.pickerNode.addSolid(self.pickerRay)
      base.cTrav.addCollider(self.pickerNP, base.handler)
###############################################################################

      if (self.keyMap["shoot"]!=0):
          self.mpos=base.mouseWatcherNode.getMouse()
          self.pickerRay.setFromLens(base.camNode, self.mpos.getX(), self.mpos.getY())
          base.cTrav.traverse(render) 
          if base.handler.getNumEntries() > 0:
            base.handler.sortEntries()
            self.pickedObj=base.handler.getEntry(0).getIntoNodePath()
            self.pickedObj=self.pickedObj.findNetTag('myObjectTag')
            if not self.pickedObj.isEmpty(): 
              print "shoot" 

The problem is probably this line:

self.pickerNode.setFromCollideMask(BitMask32.bit(0))

That turns off your picker ray as a from object so the handler never actually works. Give the from mask any number other than zero.

Actually, it says BitMask32.bit(0) which means the first bit is on, actually, so it is enabled. BitMask32(0) would have been a zero bitmask.

Ty all. So maybe its in another part of my code, i’ll play around with it, I think I got the problem actully now, let me test some of the code.

KK yea it was cus of my CollisionSphere blocking the ray from sending out. So I turn it off using

cnodePath.node().setIntoCollideMask(BitMask32.allOff())