[Solved] problem with collisions

Ok this should be relatively simple. I have four colspheres around four objects (I can see them) and when these objects collide, I should get a print statement.

I’ll only paste 2 of the four for code clarity.

self.cTrav = CollisionTraverser()
        self.cHandler = CollisionHandlerEvent()
        self.colSphere1 = createColSphere(self.players[0][0], "player1Sphere", 35, show = True)
        self.colSphere2 = createColSphere(self.players[1][0], "player2Sphere", 35, show = True)
       self.colSphere1.node().setIntoCollideMask(BitMask32.bit(16))
       self.colSphere2.node().setIntoCollideMask(BitMask32.bit(16))
       self.cTrav.addCollider(self.colSphere1, self.cHandler)
       self.cTrav.addCollider(self.colSphere2, self.cHandler)
       self.cHandler.addInPattern("player1Sphere-into-wall")
       self.cHandler.addInPattern("player2Sphere-into-wall")
       self.accept("player1Sphere-into-player2Sphere", self.pl1Into2)

The method self.pl1Into2 should print out a statement to that effect.

However, I see no such thing when I collide them. Any help?

CollisionTraverser requres that you call cTrav.traverse() every frame. Note base.cTrav does that for you … maybe this is where the confusion comes from?

Can you elaborate? Your answer’s kind of confusing.

The collision traverser checks whether any collision have occurred. There is one built-in collision traverser, that is called automatically every frame: base.cTrav
If you create any other collision traversers (for example, self.cTrav, as you did), you should call it manually by

self.cTrav.traverse(render) # you can use some other nodepath instead of render, if needed

You also need to add collision handler and colliders to the traverser, so that it knows what collisions to determine.
Then, you need some active collision node (“from” node). You only have passive “into” nodes. You can compare the “from” node with a drunk man, and the “into” node with walls and road this man collides with.
PS: The “from” nodes can also collide with each other (if they have the same collide mask, of course), just like two drunk men can. If they have different collide mask then, of course, they won’t collide with each other, just like drunk man won’t collide with drunk spook; this is because they have different collide masks :laughing:

Also i think your event pattern is not ok

I think you can check by running your code with messenger verbose

Here your second line will replace the effect of first line.
So the event fired will always be “player2Sphere-into-wall” whatever collision is detected

So the function self.pl1Into2 will never be called because the event
“player1Sphere-into-player2Sphere” will not be sent.

self.cHandler.addInPattern(’%fn-into-%in’) will send the event you look after if name of sphere1 is player1Sphere and name of sphere2 is player2Sphere

if object 1 is player1Sphere and object 2 is wall then event fired would be
“player1Sphere-into-wall”

you’re a god send.

I figured out the problems of no collisions but only 1 event was happening. Thanks!