Hello,
I’ve tried to find a solution to a long-term issue I’ve had with Bullet collisions. The problem is that whenever there’s a sloped triangle mesh, other physics objects are sucked to the other side of the sloped triangle.
I’ve produced a small test application to demonstrate this issue. There are two objects: a dynamic box falling, and a ground triangle mesh consisting of 2 triangles.
from direct.showbase.ShowBase import ShowBase
from panda3d.core import Point3, Vec3
from panda3d.bullet import *
class BulletCollisionDebugDemo(ShowBase):
def __init__(self):
ShowBase.__init__(self)
self.win.setClearColor((0, 0, 0, 1))
self.world = BulletWorld()
self.world.setGravity(Vec3(0, 0, -9.81))
self.debugNode = BulletDebugNode('Debug')
self.debugNode.showWireframe(True)
self.debugNode.showBoundingBoxes(True)
self.debugNP = render.attachNewNode(self.debugNode)
self.world.setDebugNode(self.debugNode)
self.test_floor = BulletRigidBodyNode("The floor")
p0 = Point3(2, -2, 0)
p1 = Point3(-6, -2, 0)
p2 = Point3(-6, 6, 1) # The sloped triangle
p3 = Point3(2, 6, 0)
mesh = BulletTriangleMesh()
mesh.addTriangle(p0, p1, p3) # The flat triangle
mesh.addTriangle(p1, p2, p3) # The sloped triangle
self.test_floor.addShape(BulletTriangleMeshShape(mesh, dynamic=False))
self.world.attachRigidBody(self.test_floor)
self.test_box = BulletRigidBodyNode("The box")
self.test_box.setMass(1.0)
self.test_box.setFriction(1.0)
shape = BulletBoxShape(Vec3(0.5, 0.5, 0.5))
self.test_box.addShape(shape)
np = render.attachNewNode(self.test_box)
np.setPos(-3,3,15)
self.world.attachRigidBody(self.test_box)
self.debugNP.show()
taskMgr.add(self.process, "main_process", appendTask=True)
def process(self, task):
self.dt = globalClock.getDt()
self.world.doPhysics(self.dt)
return task.cont
demo = BulletCollisionDebugDemo()
demo.run()
If you execute this code, (and zoom out fast enough ), you should see the cube falling through the triangle mesh with no intention of stopping.
In my main project, I have a player model instead of a box. What is not apparent in this demo, is that if an object moves slower, the Bullet physics immediately attempts to push the object through the triangle to the other side. And the other side of the triangle does have proper collision.
One might think that there is something wrong with the bullet setup, so as a sanity check, I’m going to set p2 = Point3(-6, 6, 0). This makes both triangles flat. The cube bounces from the ground and stops on the platform:
Any ideas why the cube ignores the sloped triangle? Running pre-built Panda3D 1.9.4 on Windows 7 64bit.