ColllisionDetection and Collision Ray

Hy everybody. Comming back to search for hellp… Last time people helped me a lot over here!!

Well, I have a problem with collision detection.

I’m detecting all the collisions I want, except from one. My collisionRay is coliding with the walls (defined in the egg file), the method

base.cTrav.showCollisions(render) 

shows me the wall turning red because the collision, but no event is generated! I don’t know what is wrong, because events are being generated right when a collisionSphere collides with the walls or when the collisionRay collides with the collisionSphere,

so, I’m, in order, calling these methods:

base.cTrav.traverse(render)
base.cTrav.showCollisions(render) 

print self.handlerQueue.getNumEntries()

for i in range(self.handlerQueue.getNumEntries()):
  	entry = self.handlerQueue.getEntry(i)
  	print entry

And although it shows me the wall red, no event is generated in the CollisionHandlerQueue (that’s called Queuehandler) and getNumEntries returns 0 everytime…

Tks just for reading!

Just to make clear… When i worte event… I intended to write entry…

Hmm, the wall is lighting up red? That’s a little strange, normally it would light up white when a collision is detected, and yellow when it approaches the bounding volume. I think it might use red if you have set the tangible flag to false on the collision polygon, though. Is that the case?

As to your problem, there are two possibilities I can think of.

(1) It is only lighting up halfway to indicate the bounding volume test is passing, but not necessarily the intersection test. (This might be easier to tell if you left the tangible flag alone, so it would light up white or yellow, as appropriate.)

(2) It is lighting up because some other collision object is intersecting the wall, but not the object associated with your handlerQueue.

Note that whichever traverser you assign to base.cTrav is automatically traversed by Panda, so you should not be traversing it explicitly. If you want to have explicit control over when the traversal is made, you should not assign it to base.cTrav. When Panda traverses base.cTrav, it might clear out the handlerQueue.

Also note that showCollisions() should be made before the call to traverse(). showCollisions() enables the flag that tells the traverser to start revealing collisions during its traversal; it doesn’t reveal the collisions previously detected.

David

David,

Tks a lot for your fast answer. When I get home from work, I’ll fix all that little mistakes and try again.

I didn’t change the value of the tangible flag, so I guess it is still with its default value.And I believe that option 2

"(2) It is lighting up because some other collision object is intersecting the wall, but not the object associated with your handlerQueue. "

is not probable, because there are no other objects around and, when I don’t creat the ray, this wall is not lighting up.

At home I’ll fix some stuff and then I tell you how the program is behaving!
Tks again.

David,

Itried to simplify the code, but I still don’t know what is wrong.

So, I’ll tell you what is my intention, then maybe it’s possible to find out the mistake:

I have a little ball that moves (a pacman). I want him to see what is in front of him.
So, I created a task to do that. Every frame I would like this task to perform the following operations:

1 Creates a CollisionSegment (it was a CollisionRay, but I changed to a CollisionSegment)
2 Attaches it to the pacman
3 Assign the collisions of that node to be controlled by the CollisionHandlerQueue
4 Verifies where the collisionSegment collided, lookign at the entries of the queue
5 Sort the entries to get the closer object
6 Get this object

It is important to remember that the pacman has a collisionSphere attached to him. It’s controlled by a HandlerPusher (so the pacman does not hit the walls of the labyrinth. And this collisionHandlerPusher is working fine.

Here is the code I did:

def pacmanVision(task):
    self.pacman.createSegment()
    base.cTrav.addCollider(self.fantasma.colSeg, self.handlerQueue)
    # This call shows the wall red that I told you
    base.cTrav.showCollisions(render) 
    #This prints zero, although the wall is red
    print self.handlerQueue.getNumEntries()

And here is the code of self.pacman.createSegment()

def createSegment(self):

     ax = self.node.getX()
     ay = self.node.getY()
     az = self.node.getZ()
     #it has length 8 and is parallel to the x axis
     bx = ax + 8
     by = ay
     bz = az
     segment = CollisionSegment(ax,ay,az,bx,by,bz)
     self.colSeg = self.node.attachNewNode(CollisionNode('pacSegment'))
     self.colSeg.node().addSolid(segment)
     self.colSeg.show()

Solved it, my task was cleaning the handlerQueue. Now iy is working. But all the collisions in the code are shown in red. I haven’t seen anything yellow.

But it is working! Tks, David

If I have other doubts, I will try to solve them there! Tks a lot

Hmm. It draws a red square at the point of intersection. Is that what you’re seeing?

David

Yes, when you look from a closer view, it is a red square that is drawn.

First of all, thanks a lot, all the collisions are now working as they should.

But I still have one doubt about the collisionSegment:

I intended to use the collisionSegment to capture what is in front of the pacman, so, I wanted something like that:

O------------

O = Pacman
---- = collisionSegment

So, I declared the collisionRay like that:


#self.node contains the nodePath of the pacman 

ax = self.node.getX()
ay = self.node.getY()
az = self.node.getZ()

segment = CollisionSegment(ax,ay,az,ax+10,ay,az)

colNode = CollisionNode('PacmanVision')		
colNode.setFromCollideMask(BitMask32(0x2))
colNode.setIntoCollideMask(BitMask32.allOff())

self.segCol = self.node.attachNewNode(colNode)
self.segCol.node().addSolid(segment)
self.segCol.show()

I imagined a CollisionSegment like that:

O-----------

But the collisionSegment is starting further from the pacman than int should, like this:

O xxxxxxxx -----------

xxxxx = blankspace between the collisionSegment and the pacman

And, when I printed

print self.segCol.getPos(self.node)

I got the result Point3(0,0,0).
I searched over here and didn’t find the answer, maybe it’s a begginer mistake!
Does anybody know what I’m doing wrong?

Tks a lot just for reading!

Remember, in the scene graph, a node inherits the transform of its parent. Since self.segCol is a child of self.node, it automatically inherits self.node’s transform, which includes its position. So if you offset self.segCol by ax, ay, az, you are apply the position offset twice.

Just declare segment like this:

segment = CollisionSegment(0, 0, 0, 10, 0, 0) 

David

When I get home after work, I’ll try that!!

Thanks a lot David! Always helping me!

Worked pretty well!!! Thanks a lot, David!