[SOLVED]Object colliding with parent (object is only child)

Ok, here is code that got me kind of confused today, it made ship move to y-negative (its collision sphere).

I am curious, is that supposed to happen…
Basically, if i set bit in “into collide bitmask” on one NP
and add NP/NP2.node() as “from object” it will push itself to y-negative in this case.

fromMask = BitMask32().allOff()
intoMask = BitMask32().allOff()
fromMask.setBit(0)
fromMask.setBit(3)
intoMask.setBit(0)
intoMask.setBit(1)
intoMask.setBit(2)

fromObject = self.shipNP.find('**/+CollisionNode')

fromObject.node().setFromCollideMask(fromMask)

#next line causes "bug"
self.shipNP.setCollideMask(intoMask)

#next line works as i want it
#fromObject.setCollideMask(intoMask)

base.cTrav.addCollider(fromObject,base.handlerEvent)

base.cTrav.addCollider(fromObject,base.pusher)

base.pusher.addCollider(fromObject,self.shipNP)

I have solved problem, but i would like to know why it was there, please answer in noob friendly way :slight_smile:

Thanks!

So from what you’re saying, you set the collide masks so that a child node could collide with its parent. And then when you ran it, the child node collided with its parent. So where’s the problem?

You could write a program like this:

x = 1
while x > 0:
  x = 2

and it will never complete. But you can’t blame Python for that.

The point is that it’s not Panda’s job to make sure that everything you ask for makes sense. It just does what you ask for; it’s your job to ask for the right things.

David

Yeah, but why object does not collide with itself (even though i set it that way) but collides with its parent?

I mean, why this pushes object.

fromObject = self.shipNP.find('**/+CollisionNode')
self.shipNP.setCollideMask(intoMask)

But this does not?

fromObject = self.shipNP.find('**/+CollisionNode')
fromObject.setCollideMask(intoMask)

My only guess is that node doesnt collide with itself, but it collides with its parent’s bounding sphere.

When you do:

self.shipNP.setCollideMask(intoMask)

it sets the collide mask on all geometry under self.shipNP to the indicated value. This includes your CollisionNode, as well as any visible geometry. Now all of this becomes collidable.

A particular CollisionNode won’t collide with itself, even if you set the bits that way, because the collision system knows this never makes sense and so it just throws it out. Otherwise, the second option would also push your object the same way.

But the collision system doesn’t check whether you’ve set the collide bits for visible geometry that’s in the same position as your fromObject. It’s got nothing to do with the bounding volumes.

David

Oh thank you very much! I understand now :slight_smile:
In case anyone wonders about same thing, proper way to deal with this would be to pass

nodeType=CollisionNode.getClassType()

argument to setCollideMask()