collision traverser being buggy

I have a tube with over 1000 rocks and one penguin sliding down it. I use one traverser for the penguin hitting all the rocks. I am aware of the limit on the amount of objects a traverser can handle, but (unless I am mistaken) the limit only applies to “from” objects.

Anyway, the code works great until you hit a certain point in the tunnel. Then it stops working for a bit. Then, confusingly, it starts working again. The locations are not random…it always stops and starts working in the same place. The rocks and collision spheres that don’t “collide” with the penguin are still being generated, because I can see them when I run the program…so I dont understand the problem.

Below is the relevant code:

def exposeJoints(self, task):

        # for each rock, we need to expose the joint, and create a collision sphere at the pos of the joint
        for i in range (1,744):
            rockName = "Rocks1:r" + str(i)
            self.rockJoint =,"modelRoot",rockName ) 
            self.rockModel = Actor.Actor("models/Ice2.egg", {'shatter' : "models/Ice2-Shatter"} )

            self.rock = Rock(self.rockJoint, self.rockModel, i, self)
  [i] = self.rock

        return Task.done

class Penguin(DirectObject):

    def __init__(self, model, w):

        self.model = model


        self.invincible = False
        self.alreadyCollided = False
        self.jumping = False
        self.enableControl = False

        # create a collision segment coming out of the penguin's front
        self.penguinSeg = CollisionSegment(0,0,1,0,15,0)
        self.penguinSegNodePath = self.model.attachNewNode(CollisionNode('penguinColSeg') )

        # collision segment comint out of the penguin's bottom (for pits)
        self.penguinPitSeg = CollisionSegment(0,0,1,0,0,-9)
        self.penguinPitSegNodePath = self.model.attachNewNode(CollisionNode('penguinPitColSeg') )

        # set up collision traverser
        self.traverser = CollisionTraverser('penguinTraverser')
        base.cTrav = self.traverser

        # initialize collision handler
	self.collisionHandler = CollisionHandlerEvent()
        # check if the from object hit any node

        for i in range (1, 500):
            if (
                string = 'penguinColSeg-again-rock'+str(i)
                self.accept(string,[i].collide, [[i], w])

            if (w.spikes.has_key(i)):
                self.accept('penguinColSeg-again-spike'+str(i), w.spikes[i].collide, [w.spikes[i], w])

        # add the collision node path and the handler to the traverser
        self.traverser.addCollider(self.penguinSegNodePath, self.collisionHandler)

    # end init

class Rock(DirectObject):

    def __init__(self, joint, model, num, w):

        self.model = model
        self.num = num
        self.joint = joint


        self.rockSphere = CollisionSphere(0, 0, 0, 1.5) 
        self.rockSphereNodePath = self.model.attachNewNode(CollisionNode('rock'+str(self.num) ) )

At first I thought maybe the penguin’s speed was causing the problem at that point in the tunnel, so I slowed down his speed to a crawl, and I get the exact same problem.

Any ideas?

Thanks in advance,


I don’t see a problem with a cusory glance over your code, so you will need to apply some detective work.

Here are some suggestions.

(1) Maybe the collision event is getting generated, but for some reason you are not responding to it. Try the command base.toggleVerbose() to turn on verbose message handling. It will tell you as each collision event is generated (along with lots and lots of other events, prepare to be spammed). You can compare the collision events generated when you hit the first rocks with those generated (if any) when you hit the later ones.

(2) Try turning on visualization of the collision test. To do this, hide (or don’t show) all of your rock collision spheres, and then do the command base.cTrav.showCollisions(render). This will automatically draw only those collision spheres it is actively testing for collisions. When a sphere comes within its bounding volume, it will draw it in a faint yellow color, and when a collision is discovered, it will draw it in the normal white color. See if your mystery rocks are getting drawn at all.