I’ve just started using Panda3D, but when I tried to re-create the sample program “Ball in maze” with Bullet physics, I’ve ran into problems. The collision detection acts very strange, the ball sometimes fall trough the floor and sometimes accelerates to a high speed sideways, passing trough the wall of the base.
I’ve recorded theese on a video: https://www.dropbox.com/s/7p2j0xft7h49hia/rec.avi?dl=0
The code I used:
from panda3d.core import loadPrcFileData
#loadPrcFileData("", "want-directtools #t")
#loadPrcFileData("", "want-tk #t")
from direct.showbase.ShowBase import ShowBase
from panda3d.core import *
from direct.task import Task
from panda3d.core import Vec3
from panda3d.bullet import BulletWorld
from panda3d.bullet import BulletRigidBodyNode
from panda3d.bullet import BulletDebugNode
from panda3d.bullet import BulletHelper
class MyApp(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.initBullet()
self.initLight()
self.setupMyMouse()
self.createMaze()
self.createBall()
self.createColl()
#self.setupBullet()
self.taskMgr.add(self.rotateTask, "RotateTask")
self.taskMgr.add(self.bulletTask, "Bullet")
mX, mY=0, 0
def rotateTask(self, task):
dt=task.time
if base.mouseWatcherNode.hasMouse():
self.mX=base.mouseWatcherNode.getMouseX()
self.mY=base.mouseWatcherNode.getMouseY()
#print(self.mX, self.Y)
self.maze.setH(self.mX*15)
self.maze.setP(-self.mY*15+90)
self.coll.setH(self.mX*20)
self.coll.setP(-self.mY*20+90)
return Task.cont
def bulletTask(self, task):
dt=task.time
self.world.doPhysics(dt)
#print(dt)
return Task.cont
def setupMyMouse(self):
base.disableMouse()
props = WindowProperties()
props.setMouseMode(WindowProperties.M_confined)
base.win.requestProperties(props)
def initLight(self):
plight = PointLight('plight')
plight.setColor(VBase4(1, 0, 0, 1))
self.plnp = render.attachNewNode(plight)
self.plnp.setPos(0, 20, 0)
blight=PointLight("BallLight")
blight.setColor(VBase4(1, 1, 1, 1))
self.blnp=render.attachNewNode(blight)
self.blnp.setPos(0, 20, 0)
# self.coll.setLight(plnp)
def initBullet(self):
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 5, 0))
debugNode = BulletDebugNode('Debug')
debugNode.showWireframe(True)
debugNode.showConstraints(True)
debugNode.showBoundingBoxes(True)
debugNode.showNormals(False)
debugNP = render.attachNewNode(debugNode)
debugNP.show()
self.world.setDebugNode(debugNode)
def createMaze(self):
self.maze = self.loader.loadModel("ez")
#self.maze.clearModelNodes()
#self.maze.reparentTo(self.render)
self.maze.setPos(0, 50, 0)
self.maze.setLight(self.plnp)
def createBall(self):
self.ballM=self.loader.loadModel("ball")
#self.ballM.clearModelNodes()
self.ball=BulletHelper.fromCollisionSolids(self.ballM, False)[0]
#print("BallShape:%s"%self.ball)
self.ball.reparentTo(self.render)
self.ball.node().setMass(1.0)
self.ball.setPos(0, 40, 0)
#self.ball.node().setDeactivationEnabled(False)
#self.ballM.reparentTo(self.ball)
#self.ballM.setLight(self.blnp)
self.world.attachRigidBody(self.ball.node())
#self.ballM.copyTo(self.ball)
def createColl(self):
self.collM=self.loader.loadModel("coll")
self.coll=BulletHelper.fromCollisionSolids(self.collM, False)[0]
self.coll.setPos(0, 50, 0)
self.coll.setH(90)
self.world.attachRigidBody(self.coll.node())
app = MyApp()
app.run()
The 3 models are exported from Blender, link to Blender file: https://www.dropbox.com/s/gohwmyu3oj20lrk/ez.blend?dl=0
(The 3 models are on the first 3 layers. Also, object Ball and BallC are exported to the same egg file)
Why does my program act that strange?