[SOLVED]What's wrong with this code??

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()

Hi

do you need self.cube.setCollideMask(BitMask32.bit(0))
I don’t see it anywhere

Unfortunately, still not working
BTW, this part

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) 

I forgot to comment the ( self.cube.setZ(self.cube.getZ()+1)) line , so this may make misunderstanding
Thanks anyway
Another ideas??!!

I don’t see any collision geometry defined for the cube. Is there any in the egg file? If not, there is no collision because there is nothing for the sphere to collide into.

The cube file egg contain the the ( { Polyset keep descend } code

What is the mean of that part??:

for i in range(len(list)): 
            if self.cHand.getNumEntries()>0: 
                if self.cHand.getEntry(0).getIntoNodePath()==list[i]:

Collide: collision entity
Polyset: polygon collision entity (wont call it solid, because its not solid, collision are active only while other collision object is touching polygons)
Keep: Use same geometry for rendering too
If there is no “keep” tag, geometry will be invisible.
Descend: Go down in Hierarchy aka:

House:
->Table
    ->Legs
    ->Tabletop
->Chair

So if you have only one object with no children, i think there is no sense in using descent property.

Someone correct me pls if i am wrong!

I see what the problem is now.
When you append the cube to list, you are appending the model, not the collision node.
To get the collision node, use something like

self.cubeCollisionNode = self.cube.find('**/Cube')
list.append(self.cubeCollisionNode)

You will need to look in the egg file to find what the name of the cube geometry is.

Thanks for the info…but I think I have to use descent property if I used collision solid even if object has no children but you have to use also the BitMask32

Yes, that was the missing link…But it’s not favorable to use the { Polyset keep descend }…By removing that code, it worked perfectly
Thank you all