import direct.directbase.DirectStart
from pandac.PandaModules import *
#initialize traverser
base.cTrav = CollisionTraverser()
#initialize pusher
pusher = CollisionHandlerPusher()
#########
#load a model. reparent it to the camera so we can move it.
s = loader.loadModel('smiley')
s.reparentTo(camera)
s.setPos(0, 25,0)
#create a collision solid for this model
cNode = CollisionNode('s')
cNode.addSolid(CollisionSphere(0,0,0,1.1))
sC = s.attachNewNode(cNode)
sC.show()
#########
#load a model
t = loader.loadModel('smiley')
t.reparentTo(render)
t.setPos(5, 25,0)
#create a collsion solid for this model
cNode = CollisionNode('t')
cNode.addSolid(CollisionSphere(0,0,0,1.1))
tC = t.attachNewNode(cNode)
tC.show()
#########
#add collision node to the traverser and the pusher
base.cTrav.addCollider(tC.node(),pusher)
pusher.addCollider(tC,t, base.drive.node())
#########
#have the one ball moving to help show what is happening
p = t.posInterval(5,Point3(0,25,0),startPos=Point3(5,25,0)).loop()
#########
#run the world. move around with the mouse to see how the moving ball changes course to avoid
the one attached to the camera.
run()
|