Bullet Collison Solids

Hey all,
I’m trying to set up some bullet collision between a shape and a loaded egg model with a collision mesh, but I’m not having a very good go of it. The source is the stack of blocks, and it’s set up to move the model by pressing the w key and it should hit the ground plane / bottom box, but it falls right through both (although keyboard input does work) Any ideas of what I’m doing wrong?

Source:

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from panda3d.core import Vec3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletPlaneShape
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletBoxShape
from panda3d.bullet import BulletCharacterControllerNode, BulletCapsuleShape, ZUp
from panda3d.core import BitMask32
 
class Realm(DirectObject):
	def __init__(self):
		base.cam.setPos(10, -30, 20)
		base.cam.lookAt(0, 0, 5)
		 
		# World
		self.world = BulletWorld()
		self.world.setGravity(Vec3(0, 0, -9.81))
		 
		# Plane
		shape = BulletPlaneShape(Vec3(0, 0, 1), 1)
		node = BulletRigidBodyNode('Ground')
		node.addShape(shape)
		np = render.attachNewNode(node)
		np.setPos(0, 0, -2)
		self.world.attachRigidBody(node)
		 
		# Stacked Boxes
		model = loader.loadModel('models/box.egg')
		model.setPos(-0.5, -0.5, -0.5)
		model.flattenLight()
		shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
		for i in range (10):
			node = BulletRigidBodyNode('BoxS')
			node.setMass(1.0)
			node.addShape(shape)
			np = render.attachNewNode(node)
			np.setPos(0, 0, i*2)
			self.world.attachRigidBody(node)
			model.copyTo(np)
			
		# Wrecking box
		playerModel = loader.loadModel('models/Wooden_Box.egg')
		playerModel.setPos(-0.5, -0.5, -0.5)
		playerModel.flattenLight()
		playerModel.find("**/Wooden_Crate_Collisio").setCollideMask(BitMask32.allOn())
		self.playerNode = BulletRigidBodyNode('BoxW')
		self.playerNode.setMass(1.0)
		
		self.playerNP = render.attachNewNode(self.playerNode)
		self.playerNP.setPos(-2, 0, 3)
		self.world.attachRigidBody(self.playerNP.node())
		playerModel.copyTo(self.playerNP)
		
		
		#keypboard input
		self.accept('w', self.moveRight)
		self.accept('w-repeat', self.moveRight)
		self.accept('s', self.moveLeft)
		self.accept('s-repeat', self.moveLeft)
	
	def moveRight(self):
		curPos = self.playerNP.getPos()
		self.playerNP.setPos(curPos[0] + 1, curPos[1], curPos[2])
	def moveLeft(self):
		curPos = self.playerNP.getPos()
		self.playerNP.setPos(curPos[0] - 1, curPos[1], curPos[2])
		
	 
	# Update
	def update(self, task):
	  dt = globalClock.getDt()
	  self.world.doPhysics(dt)
	  return task.cont
 
r = Realm()
taskMgr.add(r.update, 'update')
run()

Thanks :slight_smile:

Your player model (‘BoxW’, self.playerNode) does not have a collision shape. No collision shape --> no collision with other shapes.

Another tip: moving a dynamic object around by setting it’s position is not recommended. Use forces to move the object around. setPos should be used only for the initial position, or for “teleportations”.