Collisions

Hi everyone, I’m new to Panda Community :slight_smile:

I’m trying to solve a simple problem. I have a sphere that moves from point to point as a Sequence (points randomly generated) and a plane. What i need is to detect when the sphere collides with the plane. I just need a flag telling me “Collision!” or not. I think the easiest way is to report my few codelines. If I run the code, number of entries is always 0 even if graphically I see the collision.
Feel free to correct/suggest new code :slight_smile:

Thank you very much for your help :slight_smile:

(self.ball2 is my sphere, and self.ramp2 is the plane)

##################COLLISIONS######################

    base.cTrav = CollisionTraverser() 
    base.cTrav.showCollisions(render)
    self.handler = CollisionHandlerQueue() 
 
    self.collball = self.ball2.attachNewNode(CollisionNode("ballcoll")) 
    self.collball.node().addSolid(CollisionSphere(0, 0, 0, 1.5)) 
    self.collball.show() 
    self.collramp = self.ramp2.attachNewNode(CollisionNode("rampcoll")) 
    self.collramp.node().addSolid(CollisionPlane(Plane(Vec3(0, 0, 1), Point3(0, 0, 0.5)))) 
    self.collramp.show() 
    
    base.cTrav.addCollider(self.collball, self.handler)
    base.cTrav.addCollider(self.collramp, self.handler)

##################################################

    for i in range(self.handler.getNumEntries()):  
        entry = self.handler.getEntry(i)  
        print entry
    
    print "Number of entries: "
    print self.handler.getNumEntries()
       
   
        etc etc

I am pretty sure you should not be adding the Into object in the Travesser.
Which I believe is this line in your case:

base.cTrav.addCollider(self.collramp, self.handler) 

Take a look at the from and into objects in the manual to be sure.

Thank you! You are right.

Anyway I changed my mind and started using ODE. Now it’s easier and I solved the problem :slight_smile: