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
result=self.level.world.contactTest(self.body)
if result.getNumContacts()==0:
return task.cont
else:
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
self.explotar(pos)
self.level.Base.taskMgr.remove("contactTask_"+self.name)
self.level.Base.taskMgr.remove("Autodestroy_"+self.name)
self.level.world.removeRigidBody(self.body)
self.vMesh.detachNode()
self.bodyNP.detachNode()
print"Destroy",self.name
morterosDict[self.name]=None
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
-Edit
i just simply want that when my proyectile collide the first time it call some function, something like this
result=world.contactTest(proyectile)
if result.getNumContacts>0:
doSomething()
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.
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?
def contactTask(self,task):
global pause
result=self.level.world.contactTest(self.body)
for c in result.getContacts():
self.destroy()
break
return task.cont
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: