Collision detection, and picking

Hi all,

I have been going through the collision detection and picking segment of the tutorials. Must the collision traveser be self.cTrav and must the picker be self.picker all the time?

[color=green]Yep. That it would. We’ve been having some troubles with them for now, but those are the only things you can use. ^,^;

Actually, no, that’s not true. You can call the collision traverser anything you like. By convention, there is one collision traverser that is run automatically, and that is the one that you store in base.cTrav. If you don’t want to store your collision traverser in base.cTrav, then you have to start your own task to run it every frame. The documentation in the manual, specifically the “collision traversers” page, talks about this in more detail.

To use the Picker class, you have to create an instance of the Picker class. It doesn’t matter what name you call this instance. It can be self.picker, or self.dooby, or self.dingleberry if you prefer. You can have as many Picker instances as you like.


[color=green]Well that could be one reason we are having some problems with collision detecting.

Ok, due to the fact that this seems the most recent thread with the picking thingie, here my 2 cents/big problem.

What do I intend? Create a surface where avatars can move using a lerp from their local position to a position I give them by clicking with the mouse at the desired position. I don’t want to pick the whole surface. I just want to provide the position I get from the cursor over to the lerp (what I am going to implement later. For now I would be happy with printing this out)

Whats the problem? After mixing 2 collision tutorials and “Cloaks” help in the IRC Channel I got this whole thing partial working. However, I never manage to keep getting constantly coordinates - or coords at all.

So maybe one of you could be as kind and take a look into this where I made my mistake?
Anyways, here is the code.

import direct.directbase.DirectStart
from direct.showbase import DirectObject
from pandac.PandaModules import *

class Picker(DirectObject.DirectObject):
   def __init__(self, intoNodePath):
      self.picker= CollisionTraverser()
      self.picker.addCollider(self.pickerNode, self.queue)
      self.accept('mouse1', self.printMe)

   def getObjectHit(self, mpos): #mpos is the position of the mouse on the screen
      self.pickerRay.setFromLens(base.camNode, mpos.getX(),mpos.getY())
      if self.queue.getNumEntries() > 0:
         #print 'Position of the surface clicked: ',self.pos
      return None

   def getPickedObj(self):
         return self.pickedObj

   def printMe(self):
         self.getObjectHit( base.mouseWatcherNode.getMouse())
         print self.position

cm = CardMaker('Card')
card = render.attachNewNode(cm.generate())



Help REALLY appreciated… I am starting giving up on this - really.
Thanks in advance,


Your problem is here:

Instead of that, do this instead:

This is because you parent your picker to the node ‘camera’, not to the node ‘’. When you move, you are moving it independently of camera, so the picker no longer lines up to where your camera is looking.

In fact, you should never move independently of camera anyway. The idea is supposed to be that is always in the same space as camera, unless you call base.oobe().


:open_mouth: You are right… that fixed it. Its working perfect now! :smiley:

Thanks & regards, Bigfoot29