Problems with setting up collision detection

I’m having some trouble setting up collision detection.
I read the manual and tried out the ralph demo but when
I try to setup collision detection for my own project I
can’t get it to work.

#basic collision detection setup!
base.cTrav = CollisionTraverser()
self.collisionSphere = CollisionSphere(0, 0, 0, 10) 
self.collisionPath = self.arie.ralph.attachNewNode(CollisionNode('cNode')) 
#we will show the collision sphere just for testing purposes!
#assign a handle to the queue
self.collisionHandle = CollisionHandlerQueue()
base.cTrav.addCollider(self.collisionPath, self.collisionHandle)
#do the actual collision detection!
#print self.collisionTraverser.
for i in range(self.collisionHandle.getNumEntries()):
    entry = self.collisionHandle.getEntry(i)
    print 'collision detected' + entry
    print 'woot!'
    print 'no collision detected'

Why did you define two collisionHandlerQueue ?
Are “queue” and “self.collisionHandle” representing the same thing ? If no, try to replace “queue” by “self.collisionHandle”

These tutorials are pretty easy:

Thanks for the quick reply. Even when changing queue to self.collisionhandler it doesn’t work. Unfortunally I don’t have the possibility to download files now. Hopefully someone can tell me what is wrong with my code

clooner I would try to help but you should first send your code enclosed into

your code here

tags otherwise ppl willing to help can’t easy understand where is the problem in your messy indented code.

Thanks! I’ll try and edit the post. I got a question though. In the manual it says that every object what I put in the scene becomes automatically an into object. Therefor I don’t need to assign this true?

short question, short reply: yep! :wink:

then why doesn’t my code work

sorry clooner I saw just afterwards you fixed the code viewing.

first off I need to see the other object setup you’re try to collide with - you just made me see the into but I don’t see any from object there. Anyhow, I strongly suggest you first to pass through the beginner package kindly suggested above by Anon, that I wrote to answer this kind of simple questions indeed, and that should wipe your doubts but if not just come back here again (or better put there your other doubts) and you’ll be followed again.

Thanks for the insight. I believed this was the code to setup the from collider and all the objects in the scene are already the into objects. So you only have to setup a from collider and then you already have basic collision detection. What you are saying is that I setup my avatar as a into collider? Ps the only Internet I have is on my phone therefor I am unable to download files

nope - basically you just need to setup a FROM object, remember we said the intos are automatically defined.

you of course meant you can download BIG files - small files have been always downloaded since the 8kb modems - anyhow that’s a problem I ain’t thought of while making my packages and I’ll take care soon providing lightweight packages for situation like yours.
But keep in mind that here we are all ppl willing to help but with very thin time windows therefore these kind of very basic issues are generally up to the newbie, that following the always precious panda3D manual or previous forum topics have wiped out from long time, generally will get rid of by themselves.

I can get it to work if I manually set each object as into collide objects but the manual states this already happens automatically so is the manual wrong? Also I checked to reference and I can only see that I set my from object correctly.


ok stop - we need to clear this mess - today I’m busy and I made a mess here because I ain’t put much attention. I provided you here a working piece of code should clear one for all this issue - here you’ll find how to settle properly a FROM and an INTO objects and what’s the difference between them. Inquire me again otherwise:

from pandac.PandaModules import CollisionHandlerQueue, CollisionNode, CollisionSphere, CollisionTraverser
import direct.directbase.DirectStart
collisionHandler = CollisionHandlerQueue()

# This is the FROM object because we add it to the main traverser (see below)
frowneyModel = loader.loadModel('frowney')
frowneyCollider = frowneyModel.attachNewNode(CollisionNode('frowneycnode'))
frowneyCollider.node().addSolid(CollisionSphere(0, 0, 0, 1))
frowneyModel.setPos(2, 25,0)
# now this became the FROM object
base.cTrav.addCollider(frowneyCollider, collisionHandler)

# this will be anutomatically considered as an into object by the system
smileyModel = loader.loadModel('smiley')
smileyModel.setPos(-2, 25,0)
smileyCollider = smileyModel.attachNewNode(CollisionNode('smileycnode'))
smileyCollider.node().addSolid(CollisionSphere(0, 0, 0, 1))

def traverseTask(task=None):
  for i in range(collisionHandler.getNumEntries()):
    print "You touch me!"
    if task: return task.again

  if task: return task.again

taskMgr.doMethodLater(.2, traverseTask, "tsk_traverse")