BTW, here is the working example on which I am experimenting. Anybody should be able to run it out of the box. Hope it will help to diagnose the issue:
from functools import partial
from direct.showbase.ShowBase import ShowBase
from direct.actor.Actor import Actor
from panda3d.bullet import BulletCapsuleShape, BulletCharacterControllerNode, ZUp, BulletWorld, BulletDebugNode, BulletPlaneShape, BulletRigidBodyNode
from panda3d.core import Vec3
JUMP_SPEED = 5
class Test(ShowBase):
def __init__(self):
ShowBase.__init__(self)
#WORLD SETUP
base.world = BulletWorld()
base.world.setGravity(Vec3(0, 0, -9.81))
#DEBUG STUFF
debugNode = BulletDebugNode('Debug')
debugNode.showWireframe(True)
debugNode.showConstraints(True)
debugNode.showBoundingBoxes(True)
debugNode.showNormals(True)
debugNP = render.attachNewNode(debugNode)
debugNP.show()
base.world.setDebugNode(debugNP.node())
#GROUND
sceneCollider = BulletPlaneShape(Vec3(0,0,1),0)
node = BulletRigidBodyNode()
node.addShape(sceneCollider)
np = render.attachNewNode(node)
np.setPos(0, 0, 0)
base.world.attachRigidBody(node)
#PHYSICS
#I think I should do something here but what? :-/
#PANDA 1(CONTROLLED BY ME)
self.actor = Actor("models/panda-model",
{"walk": "models/panda-walk4"})
shape = BulletCapsuleShape(500,1,ZUp)
self.controller = BulletCharacterControllerNode(shape,.4,'Controller1')
self.charNP = render.attachNewNode(self.controller)
base.world.attach(self.controller)
self.actor.reparentTo(self.charNP)
self.controller.setJumpSpeed(JUMP_SPEED)
self.charNP.reparentTo(render)
#PANDA 2(NPC)
self.actor2 = Actor("models/panda-model",
{"walk": "models/panda-walk4"})
shape = BulletCapsuleShape(500,1,ZUp)
self.controller2 = BulletCharacterControllerNode(shape,.4,'Controller2')
self.charNP2 = render.attachNewNode(self.controller2)
base.world.attach(self.controller2)
self.actor2.reparentTo(self.charNP2)
self.controller2.setJumpSpeed(JUMP_SPEED)
self.charNP2.reparentTo(render)
self.charNP2.setPos(0,-1500,0)
self.charNP2.setH(180)
#INPUT
self.accept('a',partial(self.move,0))
self.accept('d',partial(self.move,1))
self.accept('a-up',partial(self.move,2))
self.accept('d-up',partial(self.move,2))
base.taskMgr.add(self.updatePhysicalWorld,'updatePhysicalWorld')
base.taskMgr.add(self.cameraTask,'cameraTask')
def move(self,direction):
if direction == 0:
self.controller.setLinearMovement(Vec3(0,-200,0),True)
elif direction == 1:
self.controller.setLinearMovement(Vec3(0,200,0),True)
else:
self.controller.setLinearMovement(Vec3(0,0,0),True)
def updatePhysicalWorld(self,task):
dt = globalClock.getDt()
self.world.doPhysics(dt)
return task.cont
def cameraTask(self,task):
base.cam.setPos(self.actor.getPos() + Vec3(6500,0,500))
base.cam.lookAt(self.actor)
return task.cont
test = Test()
test.run()