regarding handlers and pushers...

We are currently working on a tank game with a collision sphere around the tank. The sphere is a pusher, and its collideMaskBit on the sphere matches the bit on all the walls, so it only pushes against the walls.

I’m trying to place rocks in the level with collision polygons in front of the rocks which will also react to the sphere. I want the rock polys to push against the tank, which i know how to do.

The tank is also equipped with lasers, which allows it to blow up rocks. To simulate a laser blast, I’m using a collisionSegment in front of the tank, which is moved around by the mouse.

My problem is this: is it possible to have the polygons in front of the rocks push against the tank, but also react to the collision segment used for laser fire? One of my friends was trying something like this, but he was having trouble adding the same collision polygon to the traverser twice (once for the pusher, and again for the collision handler).

My idea was once the polygon gets hit by the laser, play a rock animation, then detach the rock from the sceneGraph, which would get rid of the polygon (the polygon would be parented to the rock, of course), and allow the player to pass.

I guess my question is how can I have the polygon act as a pusher on the sphere and a produce a collision event on the laser collisionSegment? Or is the answer easy, and am I complicating things?

I don’t think you want to add the rocks to the collision traverser. Just add the tank sphere and its laser. The rocks should be “into objects”, and they can respond to collision from the tank sphere and from the laser as separate events.

David

the thing is, I don’t want an event on the tank sphere, I just want the rocks to push on the sphere so the tank can’t go through them.

So to do this, do I just make sure the bitmask on the rocks matches both the bitmask on the tank sphere AND the bitmask on the laserSegment?

Right. Make sure the collide bits match, that’s all that matters. You don’t need to generate (or listen for) an event on the tank sphere if you don’t care about that.

David

so if I did


self.rockSphereNP.node().setCollideMask(BitMask32.bit(4))

and then


self.rockSphereNP.node().setCollideMask(BitMask32.bit(1))

would that set both bits 1 and 4? Or do I have to do something special?

Thanks again for your help David, I appreciate the quick response :smiley:

nevermind, i figured it out

I used self.rockSphereNP.node().setCollideMask(BitMask32(18) )

since bit1 = 2 and bit4 = 16 :wink:

But I couldn’t find this “addition” answer anywhere online, I had to call some of my friends. Perhaps you guys should post this in the manual, or did I miss it?

If you are worried about matching all of the bits in the mask, you dont have to do addition. You can define the mask beforehand and then set it to the collision node.

mask = BitMask32().allOff()
mask.setBit(1)
mask.setBit(4)
self.rockSphereNP.node().setCollideMask(mask)

ahh I have to instantiate a BitMask32 before I can use setBit. I had tried using setBit before and it wasnt working, now I know why.

Thanks russ.