[SOLVED] bullet fired into the barrel, world.contactTest ...

When a bullet fired into the barrel, world.contactTest unable to detect collisions.

Please watch a video:
tudou.com/programs/view/vMrw8D4xpt4/

In this video, there are a number of bullets fired into the barrel, and the barrel has also undergone a move, but did not trigger an explosion by world.contactTes .

When I fired, will be added a NodePath into self.bullet list .

def on_click(self):
	shape = BulletCylinderShape(0.006, 0.02, YUp)
	node = BulletRigidBodyNode('cylinder')
	node.setMass(0.02)
	node.addShape(shape)

	node.setCcdMotionThreshold(1e-7)
	node.setCcdSweptSphereRadius(0.01)
	node.setLinearVelo ... # Calculating the direction of the bullet, the bullet speed of 247m/s.

	np = render.attachNewNode(node)
	...
	self.world.attachRigidBody(node)
	...

	self.bullet.append(np) # Add a bullet into self.bullet list.

Here, each frame is checked Collision:

def update(self, task):
	self.world.doPhysics(globalClock.getDt(), 50, 0.001)

	for np in self.bullet:
		result = self.world.contactTest(np.node())
		for contact in result.getContacts():
			mpoint = contact.getManifoldPoint()
			e = loader.loadModel('textures/explosion')
			e.setPos(mpoint.getPositionWorldOnA()+(0,0,-0.6))
			e.setBillboardPointEye()
			e.reparentTo(render)
			taskMgr.doMethodLater(1.6 ,e.detachNode,'Remove explosion',extraArgs = [])

	return task.cont

vorticity

###############################################################################################

I might ask a question:
I used “egg-texture-cards” panda3d.org/manual/index.php … _Animation make explosion, this is my explosion.egg file:

<Comment> {
  "egg-texture-cards -o explosion.egg -fps 30 AnimatedExplosion_ME01.png AnimatedExplosion_ME02.png Ani ..."
}
<Texture> AnimatedExplosion_ME50 {
  AnimatedExplosion_ME50.png
}
<Texture> AnimatedExplosion_ME49 {
  AnimatedExplosion_ME49.png
}
...
...
...
<Texture> AnimatedExplosion_ME02 {
  AnimatedExplosion_ME02.png
}
<Texture> AnimatedExplosion_ME01 {
  AnimatedExplosion_ME01.png
}
<Material> explosion {
  <Scalar> emitr { 1.00 }
  <Scalar> emitg { 1.00 }
  <Scalar> emitb { 1.00 }
}
<Group> {
  <Switch> { 1 }
  <Scalar> fps { 30 }
  <VertexPool> vpool {
    <Vertex> 0 {
      -2 4 1
      <UV> { 0 1 }
    }
    <Vertex> 1 {
      -2 0 1
      <UV> { 0 0 }
    }
    <Vertex> 2 {
      2 0 1
      <UV> { 1 0 }
    }
    <Vertex> 3 {
      2 4 1
      <UV> { 1 1 }
    }
  }
  <Group> AnimatedExplosion_ME01 {
    <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { AnimatedExplosion_ME01 }
      <MRef> { explosion }
      <VertexRef> { 0 1 2 3 <Ref> { vpool } }
    }
  }
...
...
...
  <Group> AnimatedExplosion_ME50 {
    <Polygon> {
      <RGBA> { 1 1 1 1 }
      <TRef> { AnimatedExplosion_ME50 }
      <VertexRef> { 0 1 2 3 <Ref> { vpool } }
    }
  }
}

But when I load it and reparent to render, It is not necessarily from the first frame playback. So, when a explosion, the explosion effect maybe to the half, and then play from start to half.

I assume you have by now fixed the CCD problem according to your other task, meaning

  • the stepsize is back from 0.001 to a reasonable size (1/60, 1/120, 1/180 seconds)
  • the CCD swept sphere radius is larger than 0.01

The bullet should hit the barrel now, and bounce off. If not you don’t need to read on, but go back to your other thread. This needs to be fixed first!

world.contactTest just checks for contacts at the point of time when you invoke the method. This means that if in the first frame you bullet is a little bit in front of the barrel it won’t return any contact results, and in the next frame it already has bounced off and thus is no longer in contact with the barrel. So both frames won’t provide contact results, since the bullet is not in contact with the barrel.

What you could do is to enable collision events for the barrel (or bullet), and handle the explosion from within the event callback.

Danke!

I used notifyCollisions, then the code worked well.

self.world.doPhysics(globalClock.getDt(), 15, 0.002)

tudou.com/programs/view/CCxvZ5Pi01g/

Now I just have one question - about animation texture. Animation texture play without first frame.

Should I ask this question in the forum Pipeline?

You can do:

model.find('**/+SequenceNode').node().play()

to reset the frame to the first frame whenever you’re ready.

David

haha, Problem solved, thank you.