Clicking in an object

Hi all

I’m trying to select an object by clicking on it with the left mouse button. I hover the mouse over the panda and click, but nothing happens apparently. This is the code involved:

class World(DirectObject):

	def __init__(self):

		#Collision traverser
		self.picker = CollisionTraverser()

		#Collision handler
		self.pq = CollisionHandlerQueue()

		#Collision ray
		self.pickerNode = CollisionNode('mouseRay')
		self.pickerNP = camera.attachNewNode(self.pickerNode)
		self.pickerRay = CollisionRay()               #Make our ray
		self.pickerNode.addSolid(self.pickerRay)      #Add it to the collision node
		self.picker.addCollider(self.pickerNP, self.pq)
		self.pandaActor.setTag('pandaActorTag', '1')
	def click(self):
		mpos = base.mouseWatcherNode.getMouse()
		self.pickerRay.setFromLens(base.camNode, mpos.getX(), mpos.getY())
		#assume for simplicity's sake that myHandler is a CollisionHandlerQueue
		if self.pq.getNumEntries() > 0:
			self.pq.sortEntries() #this is so we get the closest object
			print "You have clicked on the panda"
			if not pickedObj.isEmpty():
				print "You have clicked on the panda"

Any suggestion? I can post the whole code if it helps, but I didn’t want to put everything as it is a bit long.


did you passed here?
if not, it is a little snippet showing off how to select an object or even bunch of objects clicking and dragging a rectangle. check that out and maybe you’ll find there your answers