Hello all…
I want to make collision between a sphere object and a cube object so I putted a collisionNode attached to the sphere object then collisionSolid and bla…bla…bla, then I intend (for some reasons) to make the detection of (IntoNode) which is the cube object is performed using the nodepath itself not the name of collisionNode but it didn’t work…What is the problem in the code??..Here is the code and the important part the (def prin(self)) part
import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
from panda3d.core import CollisionSphere,CollisionNode,CollisionHandlerQueue,CollisionTraverser,BitMask32
class Cube(DirectObject):
def __init__(self):
self.cube=loader.loadModel("cube")
self.cube.reparentTo(render)
list.append(self.cube)
def setThePos(self,PosX,PosY,PosZ):
self.cube.setPos(PosX,PosY,PosZ)
class Sphere(DirectObject):
def __init__(self):
self.sphere=loader.loadModel("sphere")
self.sphere.reparentTo(render)
self.sphere.setPos(0,-5,0)
self.CN=CollisionNode("CCNN")
self.CNP=self.sphere.attachNewNode(self.CN)
self.CN.setFromCollideMask(BitMask32.bit(0))
self.CS=CollisionSphere(0,0,0,1)
self.CNP.show()
self.CN.addSolid(self.CS)
self.cHand=CollisionHandlerQueue()
self.cTrav=CollisionTraverser()
self.cTrav.addCollider(self.CNP,self.cHand)
self.cTrav.showCollisions(render)
taskMgr.add(self.move,"move")
self.accept("arrow_right",self.right)
self.accept("arrow_left",self.left)
self.accept("arrow_up",self.up)
self.accept("arrow_down",self.down)
self.accept("control",self.prin)
def prin(self):
for i in range(len(list)):
if self.cHand.getNumEntries()>0:
if self.cHand.getEntry(0).getIntoNodePath()==list[i]:
list[i].setZ(list[i].getZ()+1)
self.cube.setZ(self.cube.getZ()+1)
def move(self,task):
self.cTrav.traverse(render)
return Task.cont
def right(self):
self.sphere.setX(self.sphere.getX()+1)
def left(self):
self.sphere.setX(self.sphere.getX()-1)
def up(self):
self.sphere.setY(self.sphere.getY()+1)
def down(self):
self.sphere.setY(self.sphere.getY()-1)
global list
list=[]
c=Sphere()
x=Cube()
x.setThePos(5,0,0)
x=Cube()
x.setThePos(-5,0,0)
x=Cube()
x.setThePos(0,0,0)
run()