npc dissapearing

I have an npc that I want to shoot, so I am thinking I will add collision spheres to the npc and pick the npc while aiming and shooting to determine whether the shot was accurate. But as soon as I add the collision sphere to the npc the npc disappears. I know he is still there because he triggers a conversation window when he reaches a certain point in the game world, and that window is triggerd.

    #self.collider.node().addSolid(CollisionSphere(0, 0, 0, 1))

If the above line is commented out the player appears, if it is not commented the player disappears. This might be pertinent, I’m not sure, but this npc is the second instance of the same Actor used in the game world. Any thoughts appreciated.

Sometimes I’ve seen problems with a node that collides with itself. It then tries to push itself out of its own space, and ends up very rapidly chasing itself all the way to infinity. The net result is that it seems to disappear immediately (because it is suddenly very far away).

You could check if that is what is happening in your case by printing the position of your actor. If it is, make sure that it is not colliding with itself, by ensuring that your CollisionNode doesn’t have any from bits in common with its into bits.

If by “instance” you mean that you have created a second instance of the actor using instanceTo(), then keep in mind that all instances share the same node, and therefore all of the same children; so if you add a CollisionNode as the child of one instance, you have also added it as the child of all of the instances. This means that if you add a CollisionNode to both instances, you have really added two CollisionNodes to both of them.


Thanks David, that seems to be the problem as the z value increases every task continued. I have a pretty silly question regards bitmasks, am I right in thinking it is pretty irrelevant what value is passed so long as the into and the from masks that you want to collide share the same value? ie,

set from (to collide with into1) BitMask32(0x01)
set into1 (into to be collided with) BitMask32(0x01)

set into2 (not to be collided with the above from) BitMask32(0x09)

That’s the right idea, but note that BitMask32(0x01) (binary 0001) and BitMask32(0x09) (binary 1001) actually do have a bit in common. So in your example, these two objects would in fact collide with each other.

Or perhaps you thought you were talking about BitMask32.bit(1) (binary 0010) and BitMask32.bit(9) (binary 1000000000)? These two values would in fact have no bits in common. Note the very important difference between BitMask32(x) and BitMask32.bit(x).

Also, for the record, some bits are reserved. In particular, GeomNode.getDefaultCollideMask() is automatically applied to every GeomNode, unless you explicitly clear it; so if you set this bit on your from mask, your object will test for collisions with every GeomNode in the scene, potentially very expensive. In practice, GeomNode.getDefaultCollideMask() is BitMask32.bit(20), a fairly high number. That’s the only special-purpose bit in use at the moment, though we do reserve the right to use any of the bits at bit(20) through bit(31) for a future special purpose.