衝突検出とかコリジョン検出とかコリジョンディテクションとか

あまり全部理解できてないのですが、一応サンプルだけ張っておく事にする。

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.interval.IntervalGlobal import *

#initialize traverser
base.cTrav = CollisionTraverser()

#initialize pusher
pusher = CollisionHandlerPusher()

#########

#load a model. reparent it to the camera so we can move it.
smiley = loader.loadModel('smiley')
smiley.reparentTo(camera)
smiley.setPos(0, 25.5,0.5)

#create a collision solid for this model
cNode = CollisionNode('smiley')
cNode.addSolid(CollisionSphere(0,0,0,1.1))
smileyC = smiley.attachNewNode(cNode)
smileyC.show()

########

#load a model
frowney = loader.loadModel('frowney')
frowney.reparentTo(render)
frowney.setPos(5, 25,0)

#create a collsion solid for this model
cNode = CollisionNode('frowney')
cNode.addSolid(CollisionSphere(0,0,0,1.1))
frowneyC = frowney.attachNewNode(cNode)
frowneyC.show()

#########
#add collision node to the traverser and the pusher

base.cTrav.addCollider(frowneyC,pusher)
pusher.addCollider(frowneyC,frowney)

#########

#have the one ball moving to help show what is happening
frowney.posInterval(5,Point3(5,25,0),startPos=Point3(-5,25,0),fluid=1).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()