Oh no, I was wrong, my previous issue isn’t solved.
I made an example snippet.
from pandac.PandaModules import *
import direct.directbase.DirectStart
from direct.task import Task
from panda3d.bullet import *
#----------------------------------------
dlight = DirectionalLight('my dlight')
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(0,-20,0)
render.setLight(dlnp)
alight = AmbientLight('my alight')
alight.setColor(VBase4(0.5,0.5,0.5,1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)
scene = loader.loadModel('environment')
scene.reparentTo(render)
scene.setPos(0,200,-10)
#----------------------------------------
bulletworld = BulletWorld()
bulletworld.setGravity(Vec3(0, 0, -9.81))
# render bullet nodes
debugNode = BulletDebugNode('Debug')
debugNode.setVerbose(False)
debugNP = render.attachNewNode(debugNode)
debugNP.show()
debugNP.setShaderOff()
bulletworld.setDebugNode(debugNP.node())
# bullet task
def bulletTask(task):
global bulletworld
dt = globalClock.getDt()
bulletworld.doPhysics(dt)
return task.cont
taskMgr.add(bulletTask, 'bulletTask')
def createBulletMesh(nodepath, name = ''):
mesh = BulletTriangleMesh()
# create collision solids from the model geometry
geomNodeCollection = nodepath.findAllMatches('**/+GeomNode')
for nodePath in geomNodeCollection:
geomNode = nodePath.node()
for i in range(geomNode.getNumGeoms()):
geom = geomNode.getGeom(i)
mesh.addGeom(geom)
shape = BulletTriangleMeshShape(mesh, dynamic = False)
node = BulletRigidBodyNode(name)
node.addShape(shape)
return node
bulletscene = createBulletMesh(scene)
bulletsceneNP = render.attachNewNode(bulletscene)
bulletsceneNP.setPos(0,200,-10)
bulletworld.attachRigidBody(bulletscene)
def addBox(positionx, positiony, positionz, relative = render):
boxshape = BulletBoxShape(Vec3(1, 1, 1))
boxnode = BulletRigidBodyNode('Box')
boxnode.setMass(1.0)
boxnode.addShape(boxshape)
#boxnode.setDisableDeactivation(True)
boxnp = render.attachNewNode(boxnode)
boxnp.setPos(base.cam, positionx, positiony, positionz)
visiblebox = loader.loadModel('box')
visiblebox.setPos(-1,-1,-1)
visiblebox.setScale(2)
visiblebox.reparentTo(boxnp)
bulletworld.attachRigidBody(boxnode)
return boxnode, visiblebox
base.accept('enter', addBox, extraArgs = [0, 30, 2, base.cam])
def shoot():
sphereshape = BulletSphereShape(10)
spherenode = BulletRigidBodyNode('Sphere')
spherenode.setMass(0)
spherenode.addShape(sphereshape)
spherenode.setKinematic(True)
spherenp = render.attachNewNode(spherenode)
spherenp.setPos(base.cam, 0,0,0)
bulletworld.attachRigidBody(spherenode)
spherenp.setPos(base.camera.getPos())
spherenp.setHpr(base.camera.getHpr())
spherenp.reparentTo(render)
def shootTask(bullet, task):
if task.frame < 24:
bullet.setY(bullet, 1)
return task.cont
else:
spherenp.removeNode()
bulletworld.removeRigidBody(spherenode)
return task.done
taskMgr.add(shootTask, 'shootTask', extraArgs = [spherenp], appendTask = True)
base.accept('mouse1', shoot)
run()
You should look at lines 67 and 87. 87 is where I set the spheres (bullets) to kinematic, which doesn’t change anything. setDisableDeactivation() (line 67) works, but it might be a performance issue later. You said that other nodes which collide with “sleeping” ones will wake them up, that’s why I think setDisableDeactivation() isn’t the best solution.