[SOLVED] Bullet through the target without trigger collision

This is my code:

	def on_click(self):

		self.playerActor.play('fire')

		# 发射子弹
		s = loader.loadModel('bullet')
		s.reparentTo(self.gunNode)
		s.wrtReparentTo(render)

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

		h = s.getH()*0.017453
		p = s.getP()*0.017453

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

		node.setCcdMotionThreshold(1e-7)
		node.setCcdSweptSphereRadius(0.01)
		node.setLinearVelocity(Vec3(math.sin(-h)*math.cos(p)*247,math.cos(h)*math.cos(p)*247,math.sin(p)*247))

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

		np = render.attachNewNode(node)
		np.setPos(s,(0,0,0))
		np.setHpr(s,(0,0,0))
		self.world.attachRigidBody(node)
		s.reparentTo(np)
		s.setPos(0,0,0)
		s.setHpr(0,0,0)

I guess setCcdMotionThreshold setting error. The bullet’s speed is 247m/s. game’s fps over 70, but in the video the fps is low.

My video:
tudou.com/programs/view/tujkI-CE93U/

By the way, I need a nice recorder tools onr linux.

How big is your target object?

According to my maths, at a speed of 247 metres per second and a frame-rate of 70 frames per second, your object is travelling roughly 3.5 metres per frame; if your objects are smaller than that along the axis on which the bullet is travelling then the bullet may very well simply skip over the target.

Have you considered using an approximation for your bullet? If hte bullet is very small, perhaps you could use line segments between the bullet’s “previous” and “current” positions, with the first hit being the one acted upon?

shape = BulletCylinderShape(0.4, 1.2, ZUp)

I used CCD (Continuous Collision Detection), and used:

self.world.doPhysics(globalClock.getDt(), 20, 0.0005)

Now the problem solved.

Making the stepsize smaller (0.0005) is a solution, but at the cost of performance. Lots of performance.

I suggest that you increase the CCD swept sphere radius. Currently you use 0.01, seems too small. Try increasing to 0.2 e.g.

node.setCcdSweptSphereRadius(0.2)
self.world.doPhysics(globalClock.getDt(), 15, 0.001)
node.setCcdSweptSphereRadius(0.5)

The program now works fine. Thank you!

By the way, could you help me with the other questions?