addCollider+Collisions & geometry+Collision Events[solve

Hi.
I’m currently in a situation where I need to get collision events between a ray and my level geometry. As I’ve understood it, you need to have all of the collision participants added with a CollisionTraverser’s addCollider to the CollisionHandlerEvent.

It’s easy with the ray, but how do I go about this with the geometry (loaded with the loader) since it has no CollisionNode that the addCollider requires? I can’t use Panda’s collision objects to represent the level in this case.

[size=75]Edit: the flaw was in bad addInPattern for the HandlerEvent.[/size]

The most recommended way to do that is in the .egg file. Put this in the top element:

<Collide> { Polyset keep descend }

This will make the geometry at that node and everything below also a collision geometry. More flags (to do different things, e.g. collision geometry only) can be found in the eggSyntax documentation.

Also note that this is a misunderstanding:

You do not need to add all of the collision participants to the traverser, and should not attempt to do so. You only need to add the “from” objects to the traverser; this is what makes them from objects. The “into” objects are tested for collisions by virtue of their being parented into the world. I think the manual tries to explain this carefully.

David

Thank you for your replies, gentlemen. Now, I think I’ve managed to isolate my problem a bit further. Using a test scene (using the same level geometry), I got the following from a collision between a CollisionSphere and the level through CollisionHandlerQueue: into render/level/character/-GeomNode []

To properly manage the events in CollisionHandlerEvent, I need to assign a tag or a name to this part of the path, but how exactly do you do that? Specifically in my case, the .egg contains multiple objects so the same name or tag needs to apply to all of them. I tried just going to the level of -GeomNode with a couple of GetChild(0) repeats and using setTag and setName on it, but the HandlerEvent didn’t seem to notice them. I know the HandlerEvent itself is fine from testing it with CollisionSolids :confused:

I’m not entirely sure what question you’re asking.

There are two ways to manage collision events when you’re using CollisionHandlerEvent.

Method (1): Generate a generic event name in response to each collision. Listen for this generic event name. In the handler function, examine the CollisionEntry details and see if it is one of the events you are interested in handling. If so, do the appropriate action; otherwise, ignore it.

Method (2): Configure the CollisionHandlerEvent object to generate very specific event name in response to each collision, for instance via the addInPattern() method. Add the appropriate hooks to listen for the particular specific event names you are interested in handling, and don’t add hooks to listen for the events you are not interested in handling.

If you are using method (1), which is probably the easiest approach, you can call entry.getIntoNodePath().getNetTag(‘yourTag’) in your event handler to query the tag value of a ‘yourTag’ key you have assigned onto that node or some parent.

If you are using method (2), you can embed the %(yourTag)it string into the inPattern to trigger a different event name according to the value of the ‘yourTag’ key.

David

The second method is the one I’ve been trying to use, along these lines for example…

level = loader.loadModel("models/test.egg")
level.getChild(0).getChild(0).setTag("level", "level")
...
self.events.addInPattern('%fn-into-%(level)it')
self.accept('ball2-into-level', self.hit)

But this doesn’t appear to trigger anything. However, maybe it will reveal what I’m doing wrong here? :blush:

Try:

messenger.toggleVerbose()

This will turn on reporting of all event names generated; you should be able to see what’s going on.

Note that you don’t need to go down to getChild(0) twice (and you probably shouldn’t). The “net tag” includes all parents, so setting the tag on level should be sufficient. If you do getChild(0).getChild(0), you risk setting the tag on the wrong node.

David