Using BitMasks
is actually pretty easy. This example will show us how.
In the
setupCollisions
method of ourCycle
class, add the following code right after the lines where we add ourCollisionSpheres
to theCollisionNode
:self.shieldCN.setIntoCollideMask(BitMask32.bit(3)) self.shieldCN.setFromCollideMask(BitMask32.bit(2))
Save the file as
CycleClass_02.py
.Modify
WorldClass_01.py
to importCycleClass_02.py
instead ofCycleClass_01.py
. Then, save it asWorldClass_02.py
and run it from the command prompt. Attempt to collide the two cycles together and we'll see them pass through each other, like in the following screenshot:
Our cycles don't collide anymore! That's because they are set to have different From and Into BitMasks
. BitMask.bit
creates a BitMask
that has the indicated bit set to 1, and all other bits set to 0. The calls to setIntoCollideMask
and setFromCollideMask
apply the masks created by BitMask.bit
to the CollisionNode...