Collition Problem - Nodes

Hi all,

I am creating a platform game, building the level in Maya. I have placed collition spheres in Maya (using mayaPandaTool3) and I am placing there objects which the player will be able to pick up. Here is my code for this :

for i in range(11):
          pickMe = self.level.find("**/pickme" + str(i))
          PositionX = pickMe.getX()
          PositionY = pickMe.getY()
          PositionZ = pickMe.getZ()
          PositionX = (PositionX * 10)  # Scaling to fit the scale of the level
          PositionY = (PositionY * 10)
          PositionZ = (PositionZ * 10)
          pickies = loader.loadModel("smiley")
          pickies.setScale(2)
          pickies.setX(PositionX)
          pickies.setY(PositionY)
          pickies.setZ(PositionZ)
          pickies.reparentTo(render)          
          pickMe.node().setIntoCollideMask(BitMask32.bit(0))
          pickMe.node().setName("pickme")
          self.pickMeStuff.append(pickMe)

So far so good. The objects appear in the stage. Now I am trying to make them dissapear whenever the collide with the player. Here is my code for this :

for i in range(self.cHandler.getNumEntries()):
            entry = self.cHandler.getEntry(i)
            name = entry.getIntoNode().getName()
            if   name == "pickme":   self.pickmeEvent(entry)

def pickmeEvent(self, cEntry):
        print "remove"        
        self.pickMeStuff.remove(cEntry.getIntoNodePath().getParent())
        cEntry.getIntoNode().getParent().remove()

And here is the error msg I get :

self.pickMeStuff.remove(cEntry.getIntoNodePath().getParent())
ValueError: list.remove(x): x not in list

I am sure it must be smt simple… any help is appreciated.

Thanks in advance.

Hmm, the intoNodePath might not precisely be the same node you actually inserted into the list, I suspect it is a parent of a child of that node, or so.

Err…

any ideas how to find out what node I did insert into the list?
or howelse I can remove them from the screen?

thanks!

I might have an answer, and I do have a problem as well:

here is my CollisionHandlerEvent, it is MOSTLY effective in detecting and removing the NodePath from the list:

def hitVirus(self, entry):
        entry.getIntoNodePath().getParent().remove()
        for vI in range(len(self.viruses)-1):
            if self.viruses[vI].collisionNodePath == entry.getIntoNodePath():
                self.viruses = self.viruses[:vI]
                if vI < len(self.viruses)-1:
                    self.viruses += self.viruses[vI+1:]
                break

Now for the problem:
in my code, a Virus has two FSM states, Move and Attack (because that’s what viruses do). As long as a Virus is in its initial “Move” state (closing in on its target), the code above works and the virus disappears when hit. If it reaches its “Attack” mode, however, it doesn’t matter if it’s hit, it does disappear but its draining attack continues to affect its target beyond removal. I’ve checked my “print(len(self.viruses))” output - the viruses are in fact removed from the list!

Here’s my “when viruses attack” code:

def gameLoop(self, task):
        base.cTrav.traverse(self.avAspect2d)
        for virus in self.viruses:
            if virus.virusFSM.state == "Attack" \
            and task.time - virus.lastDamageTime > DAMAGE_INTERVAL:
                virus.lastDamageTime = task.time
                self.base.currentHealth -= virus.damage
        return Task.cont

ideas?

Use tags :
discourse.panda3d.org/viewtopic.php?t=5410

Thanks for your reply, but still doesnt work.

I get this error from that line :

if self.pickMeStuff[I].collisionNodePath == entry.getIntoNodePath(): 
AttributeError: 'libpanda.NodePath' object has no attribute 'collisionNodePath'

Any ideas anyone?

Ok after futher tests, I release that the items from the list ARE removed, but the objects do not dissapear from the screen.

Anyone can suggest why?

Yes, you have to call removeNode first, before removing it from the list.

if its not too much of a trouble can you give me the code for that? I have been trying the whole morning and its driving me crazy.

How do you identify the node in the list and remove it?

thanks in advance.

Have you ever used yourIntoNodePath.reverseLs() ?

i did just know, and its basically telling me that all my objects are in the same egg file. I am wondering, ynjh_jo u might know, shall i use the same egg file (exported from maya) for both the stage and the pickup objects as I am doing now, or use two different ones?

I’d separate them, so I won’t overwhelme the level with tons of exactly the same dynamic object, thus the level’s .egg size can be kept minimum.

I should have clarified in mine, “collisionNodePath” is not a Panda variable, it’s the name of the collision volume’s node path that I added inside my Virus object. So replace collisionNodePath with whatever you used in your code.