handling collision detection

Hi everybody,

I’m working on the collision detection for a space game and I want the collision of two objects cause a reset.
I was successful to set up the collision solids but I cannot make the collision work. Can anybody tell me where is the mistake? (I Imported the necessary modules)
Here is the code:



cNode = CollisionNode('self.molecule1')


self.molecule1C = self.molecule1.attachNewNode(cNode)


self.cTrav.addCollider(self.molecule1C, self.collHandler)


cNode = CollisionNode('self.spaceship')


self.spaceshipC = self.spaceship.attachNewNode(cNode)


self.cTrav.addCollider(self.spaceshipC, self.collHandler)


self.accept( 'self.spaceshipC into-self.molecule1C' , self.collide)


def setupCollHandler(self)




self.cTrav = CollisionTraverser()

base.cTrav = self.cTrav


def collide(self):



Wait (1)

self.spaceship.setPos(Vec3(0, -1.5, -1))

Thanks in advance

Are you sure the event name you’re listening for matches the event name that will be generated? According to the text you have pasted, you are listening for the event ‘self.spaceshipC into-self.molecule1C’, but the event name that will be generated, based on the name you have assigned to your two collision nodes and the in pattern you have set, will be ‘self.spaceship-into-self.molecule1’. (There are no C’s in the names you have assigned via the setName() call, which is the important name–the name of the Python variable means nothing, of course. Also, you have a space instead of a hyphen before “into” in your string.

Note that you can type:


to enable a printout of every event name that is generated, which can help you to debug mismatches like this.

Note also that, since you are not listening for ‘self.molecule1-into-self.spaceship’, there is no need to add self.molecule1C to the traverser as a “from” object. In fact, doing this is not only needlessly expensive, but it can sometimes thwart the detection of ‘self.spaceship-into-self.molecule1’, depending on what your CollisionHandler does. You only want to add self.spaceshipC to the collision traverser.