Currently in the process of developing a game in which objects are classified as Pushable, Immovable, and Collectable. However, we’re having some trouble dealing with allowing the CollisionTraverser to deal with all three of these object types. The Wiki states that you should avoid multiple traversers except in special cases for performance reasons, so we don’t want to have to resort to that.
We currently have things set up so that there are three CollisionHandlers.
The first is “pusher”, a CollisionHandlerPusher, which is used to handle
when the player runs into an object that cannot be moved. It does as its name implies and pushes the player away when he/she hits an immovable object.
The seconder is “pushback”, another CollisionHandlerPusher, which allows the player to push pushable objects.
The last is a CollisionEventHandler, which fires events when the player runs over a collectable.
The problem that occurs seems to be some kind of conflict between the pusher and the event handler. If you add the event handler first, the player won’t be able to go through immovable objects. If you add the pusher first, the player wont be able to pick up collectables. If I print the contents of the CollisionTraverser it confirms that the handler added second overwrites the original. Why is this happening only two these two? The pushback is entirely unaffected.
Here are some code snippets that are pertinent to this problem:
self.pusher = CollisionHandlerPusher()
self.pushback = CollisionHandlerPusher()
self.cHandler = CollisionHandlerEvent()
self.cHandler.setInPattern("collide-%in")
self.cTrav = CollisionTraverser()
base.cTrav = self.cTrav
cNode = CollisionNode("Plane")
cNode.addSolid(cSphere)
cNode.setIntoCollideMask(BitMask32.bit(2))
cNode.setFromCollideMask( BitMask32.bit(1))
cNodePath = self.plane.attachNewNode(cNode)
######
#Comment out to remove visiblecollision sphere
#cNodePath.show()
######
self.cTrav.addCollider(cNodePath, self.cHandler)
"Set up the pushers"
for i in range(7):
self.cTrav.addCollider(self.movables[i].cNodePath, self.pushback)
self.pushback.addCollider(self.movables[i].cNodePath, self.movables[i].model)
#for i in range(2):
#self.cTrav.addCollider(self.immovables[i].cNodePath, self.cHandler)
self.cTrav.addCollider(cNodePath, self.pusher)
self.cTrav.addCollider(cNodePath, self.cHandler)
print self.cTrav
self.pusher.addCollider(cNodePath,self.plane)
self.fishSchool.setupCollision(self.plane)
I know it isn’t a bitmask problem, but we are completely at a loss here. Any help is greatly appreciated. If you need any more info let me know as well.
Thanks!