Get pos of a collisionEntry


I want to click on a 3D object and get its position.
For that, I use a CollisionTraverser. I manage to pick my object but not to get its position. All my objects I want to be picked specify a setTag(‘wall’,‘1’)

self.myTraverser = CollisionTraverser()
self.myHandler = CollisionHandlerQueue()
self.pickerNode = CollisionNode('mouseRay')
self.pickerNP = camera.attachNewNode(self.pickerNode)
self.pickerRay = CollisionRay()
self.myTraverser.addCollider(self.pickerNP, self.myHandler)

My function which is called when the mouse is clicked is :

def myFunction(self):
    self.pickerRay.setFromLens(base.camNode, x, y)
    if self.myHandler.getNumEntries() > 0:
       # This is so we get the closest object.
        entry = self.myHandler.getEntry(0)
        self.pickedObj =     self.myHandler.getEntry(0).getIntoNodePath()
        self.pickedwall = self.pickedObj.findNetTag('wall')
        if not self.pickedwall.isEmpty():
              #Position of entry
              return True
    return False

I tryed to use this method of a CollisionEntry :


But it returns me an error whereas my function returns me True :

AssertionError: has_contact_normal() at line 194 of panda/src/collide/collisionEntry.cxx

Does anybody have an idea to get the 3D position of my object ?


A CollisionRay doesn’t provide the “contact” position, but you can query the “surface” point with entry.getSurfacePoint(). Or you can simply use entry.getIntoNodePath().getPos(render) to get the overall position of your object.


Thank you !

I will use the surface point.