Bullet contactTest lag

I’m currently working in some proyectils, everything works very well except that i’m trying to call a function after the proyectile collide with anything, the problem is that the proyectil collide, then bounce 2 or 3 times and after 0.5 seconds calls the destructor function.

 def contactTask(self,task):
        global pause
        if result.getNumContacts()==0:
            return task.cont
            self.destroy() ## this should called when the body is in contact, but it's get called after 3 bounces and 0.5 seconds
    def destroy(self,t=None,pos=None):
        global morterosDict

By the way i get 3 contacts (one for every bounce) even if i turn my body to static or remove it from the world, or pause the simulation the body still bounce 3 times and then do the rest


i just simply want that when my proyectile collide the first time it call some function, something like this

if result.getNumContacts>0:

but the probelem is that doSomething() is called after 3 bounces

This sounds a bit unusual. What exactly does self.explotar do, and after which time does it return?
Might be it helps to put this line AFTER removing the body from the world.
Another thing you could change is self.bodyNP.detachNode() to removeNode().

By the way: using events might be more efficient, e.g.

loadPrcFileData('', 'bullet-enable-contact-events true')
    # Enable contact reporting
    self.accept('bullet-contact-added', self.onContactAdded)
    self.accept('bullet-contact-destroyed', self.onContactDestroyed)
  def onContactAdded(self, node1, node2):
  def onContactDestroyed(self, node1, node2):

I tried using events and the same thing happends, the rigid body collide, then bounce 2-3 times and then call
i simpliied my code like this

def contactTask(task):
          if result.getNumContacts()>0:
              print "Its collide"

The console prints after the 3rd bounce of the proyectile

the function explotar just start a particleEffect, but even without explotar, it just get callet after the third bounce

This is strange, because if there is a “bounce” then the smaller objects get reflexted by the larger one, and this means that Bullet applies forces in response to a collision, and this means that at least one contact point is created. If it was the Panda3D event queue beeing under heavy load then behaviour would be different between event and polling approaches. But you say both show the same effects.

I’m afraid I can’t help without further information. Best guess is that you have messed up something with the collision geometry, but just a guess. Can you slap up a demo which produces your problem and upload it somewhere? What stepping parameters do you use?

Edit this does not work the second time i try it


i changed my contactTask function to this:

def contactTask(self,task):
        global pause
        for c in result.getContacts():
        return task.cont

The key was the break

This is my project you can try it dropbox.com/s/m5so18vg3jzxo0p/presGame.7z

By the way my static object is a big triangle mesh, does you think it have something to do? i will separete in some other static body

The cause for the lag are your stepping parameters:

self.world.doPhysics(dt, 0)

Providing a max number of substeps of 0 makes Bullet switch to variable stepping, which is not officially supported. See: bulletphysics.org/mediawiki- … _The_World
Try something like this:

self.world.doPhysics(dt, 8, 1./200.)