CollisionTraverser And Instances

Since I’ve been playing around with this Engine I’ve noticed something -

If I create multiple instances of an object class, which have collision checks, the self.cTrav part can not be the same.

What I did was randomlize the self.cTrav part so that the instances would have a different pointer, like, self.cTrav1, self.cTrav2, and so on.

That seems to work, because if all the instance had the same variable for the pointer, the collisions would only work on the last instance.

What I want to know is, is there a better way to approach that problem?

It sounds like you’re getting your multiple instances confused somehow. If you actually have two different instances, and you store an object as self.cTrav in one, and a different object as self.cTrav in the other, you have successfully stored two different objects, and both of them should remain independent.

But if your “self” is actually referring to the same instance in both cases, then the second time you assign self.cTrav, you will be replacing the same object you assigned the first time, and now you have only stored one object (the first one is lost).

Or, perhaps you are getting confused by the base.cTrav element. By convention, there is exactly one base.cTrav element, and if you assign a CollisionTraverser to this element, then ShowBase will automatically call base.cTrav.traverse(render) for you, which activates the traverser. But you can only do this for one CollisionTraverser, which is normally sufficient for most applications (there’s not really any reason to create a new CollisionTraverser for each instance; they can all share the same one).

But if you are creating more than one CollisionTraverser, then of course you can’t assign them all to base.cTrav and expect them all to get traversed automatically; you will have to be responsible for calling self.cTrav.traverse(render) for each of them on your own.

It would probably be more efficient just to share one global CollisionTraverser, though.

Incidentally, I think this sort of question actually belongs in the “Scripting issues” forum.

David

I actually was talking about the base.cTrave. self.cTrave would just be another attribute of an instance/class.

So I guess what I am doing is correct then. That is, giving every instances it’s own version of base.cTrav. Or what ever one may call it because it can be base.anything. I realized I’m defining an attribute inside base.

Sorry I posted in General. I wasn’t really having a scripting issue, I was just trying to find out more about P3D’s behavior with instances and collision Travs. This Engine is far from anything I’ve ever tried.

If you use base.cTrav, you should just re-use the same CollisionTraverser for all of your instances, and not create a new CollisionTraverser and reassign it to base.cTrav each time.

If you want to create a new CollisionTraverser each time for some reason, then you cannot assign them all to base.cTrav, because only the last one will remain.

David