more traversers problem


I have problem with collision detection -> when there are more objects ( > 31) the collision detection fail. I’ve carefully read the manual + forums + Airblade 1.0.5 source so I realized I’ll need more than 1 traverser. But I don’t know how to make it right. my code (based on example in manual + Airblade ) looks like this:

self.playerTraverser = CollisionTraverser()
self.playerTraverser2 = CollisionTraverser()

taskMgr.add(self.traverseAll, 'traverseAll')


def loadObjX(self):
		#load a model. reparent it to the camera so we can move it.
		self.x = loader.loadModel('smiley2') 
		self.x.setPos(-5, 25,0)
		#setup a collision solid for this model
		xColl=self.initCollisionSphere(self.x, True)
                xColl[0].setIntoCollideMask( BitMask32.bit( 1 ) )
		xColl[0].setFromCollideMask( BitMask32.bit( 1 ) )

		#add this object to the traverser
		self.playerTraverser2.addCollider(xColl[0] , self.collHandEvent)
                self.accept( 'into-' + xColl[1], self.collide5)
                self.accept( 'outof-' + xColl[1], self.collide6)
        def loadObj1(self):
		#load a model. reparent it to the camera so we can move it.
		self.s = loader.loadModel('smiley')
		self.s.setPos(0, 25,0)
		#setup a collision solid for this model
		sColl=self.initCollisionSphere(self.s, True)

                sColl[0].setIntoCollideMask( BitMask32.bit( 1 ) )
		sColl[0].setFromCollideMask( BitMask32.bit( 1 ) )

		#add this object to the traverser
		self.playerTraverser.addCollider(sColl[0] , self.collHandEvent)
                self.playerTraverser2.addCollider(sColl[0] , self.collHandEvent)
                self.accept( 'into-' + sColl[1], self.collide3)
                self.accept( 'outof-' + sColl[1], self.collide4)

	def loadObj2(self):
            self.t = [None for i in range (self.maxobjs)]
            for i in range (self.maxobjs):
		#load a model. 
		self.t[i] = loader.loadModel('smiley') 
		self.t[i].setPos(5, 25,0+4*i)
		#setup a collision solid for this model
		tColl=self.initCollisionSphere(self.t[i], True)

		tColl[0].setIntoCollideMask( BitMask32.bit( 1 ))
		tColl[0].setFromCollideMask( BitMask32.bit( 1 ))

		#add this object to the traverser
		self.playerTraverser.addCollider(tColl[0], self.collHandEvent)


		#accept the events sent by the collisions
                self.accept( 'into-' + tColl[1], self.collide)
                self.accept( 'outof-' + tColl[1], self.collide2)


def collide(self, collEntry):
		hittedobj = collEntry.getFromNodePath().getParent()

def traverseAll(self, task):
                return Task.cont

any ideas ???

At first blush, it looks like you’ve got the right idea; but I’m surprised by this:

     self.playerTraverser.addCollider(sColl[0] , self.collHandEvent)
                self.playerTraverser2.addCollider(sColl[0] , self.collHandEvent) 

There’s no reason to add one object to both traversers. I suspect you are thinking that the two different traversers are in two completely different universes, but that’s not the case; objects that are added to one traverser will still detect collisions with objects that are added to the other one.

Remember, an object that has been added to a traverser will detect collisions with all other collidable objects in the scene graph, even those that have not been added to any traverser at all–that is, it’s not necessary to add the “into” objects to any traverser, just the “from” objects. And adding an object to any active traverser is sufficient to make it a “from” object.


yeah you are right thanks, at first I thought that every traverser ‘holds’ 2 groups of objects and calculates their collisions. :blush:

everything clear now 8)

Its a good point and should be emphasized more in the manual. It never talks about adding an into object to the traverser, but it never explicitly says you can leave it them out. Maybe this is because you can have an object that has both an into and from mask set than should be added to the traverser. Explaining this correctly might take careful wording.

I have also used another ‘trick’ of adding more than one collision solid to a collision node. It helps keep the number of collision nodes added to the traverser low. So if I needed to add six collision polygons and a collsion sphere to an environment, and they all have the same mask, then they go on the same node. I figure this is ok since eggs can have many polygons with the collide tag, but I never really looked into how it affects a traversers performance.

You’re right; the manual wasn’t sufficiently clear on this point. I have just added a couple of paragraphs to the end of the Collision Traversers page to emphasize the difference between “into” and “from” objects. Do you think that helps clarify things a bit more? I also reworded a paragraph near the beginning of the “Collision Solids” to underscore the advantage of combining several CollisionSolids into a single node.


It looks great.