Collisions with multiple nodes using the same model

I have several nodes using the same model. So when a collision occurs with any of them the name in the collision entry is the same.

How do I grab the information that it was “block2” or “block3” that was hit, and not just “block”?

just alike any other information

get the collision entry get get its from or to node … see
panda3d.org/apiref.php?page=CollisionEntry

Um, yeah, checked that. I didn’t see anything there that looked like it would give me the info I needed. I’ll look again…

Here is what it gives me if I use entry.getIntoNode() or getFromNode()

As you can see the CollisionNode doesn’t say that it is block1 that was hit, just that it hit block.

Well, getNodePath gives me this:

Somewhat helpful, I guess I will just have to figure out how to use that. Unless there is a way to get just “block1” from it…

It’s the name of the collision node.
Read for more :
discourse.panda3d.org/viewtopic.php?t=3499

You’re looking for the name of an ancestor node. For this you can either write a loop to call getParent() until you find the node you’re looking for, or you can set a tag on the ancestor nodes and call findNetTag() to have Panda do the loop for you (a tiny bit faster than doing it in Python).

David

Well, I found one way. I just search the getIntoNodePath for what I am looking for.

    intoHit = colEntry.getIntoNodePath()
    if intoHit.find("block01"): self.blockNode01.detachNode()
    if intoHit.find("block02"): self.blockNode02.detachNode()
    if intoHit.find("block03"): self.blockNode03.detachNode()

Seems to work. But detachNode gets rid of all the block nodes, instead of just the one I am telling it to. Here is the code I use to load the blocks:

    self.blockNode01 = self.playBoard.attachNewNode("block01")
    self.block01 = loader.loadModel("models/block")
    self.block01.reparentTo(self.blockNode01)
    self.block01.setPos(startX+7,startY,startZ)

    self.blockNode02 = self.playBoard.attachNewNode("block02")
    self.block02 = loader.loadModel("models/block")
    self.block02.reparentTo(self.blockNode02)
    self.block02.setPos(self.block01.getX()+7,startY,startZ)

    self.blockNode03 = self.playBoard.attachNewNode("block03")
    self.block03 = loader.loadModel("models/block")
    self.block03.reparentTo(self.blockNode03)
    self.block03.setPos(self.block02.getX()+7,startY,startZ)

So how do I get it just to remove the block that had a collision?

goes off to look at the manual more

Edit: Oh, it’s cause all the if statements return true…

So I am trying to do it like you say. I use:

self.blockNode01.setTag("block01","blocks")

to set the tag. And then:

if intoHit.findNetTag("block01"): self.blockNode01.remove()

to check to see what was hit, and remove it.

But it removes all the blocks except the one that was hit. Am I using the tags wrong? I read the documentation on the functions, but it wasn’t very clear…

Just to let you know, I solved it. I converted the intoHit from one of the posts above into a string and used that to compare with. :smiley:

NodePath.find() and NodePath.findNetTag() both always returns a NodePath, not a bool. And if they fail to find what they’re looking for, they return an empty NodePath, not None. An empty NodePath is still considered a True value by Python, which is why your attempts like:

if foo.find("blah"):

and:

if foo.findNetTag("blah"):

are always going execute the body of the if, regardless of whether the find succeeded or not. You could do something like this instead:

if not foo.find("blah").isEmpty():

David