Collision "accept" issues with the same conditions when paired together? (Solved)

Hello Panda3d community, I,m starting my next project and I decided to built it off my prevous code, so I decided to make some optimizations to it, all was going well within the last couple of days.

However, yesterday I ran into a issue, within my code when I paired two accepts with the same conditions but different functions together, here is a example below.

base.accept(“player-again-object”, base.touch)
base.accept(“player-again-object”, base.tap)

So basically I have two different functions where you enter a collision sphere, one flags a variable as True while the other is a list of effects that occur when made contact, I know they work because the one on the bottom works.

So I swap them to test, and yes only the bottom registers, so what do you think is it? I think is may be panda3d thinking the top line is redundant code and ignoring it, I may have some validation to this as I have second set accept lines in another branch just above this set.

The difference between this set and the other is.

base.accept(“player-again-object”, base.textenter)
base.accept(“player-out-object”, base.textexit)

Is the conditions are different by just a bit, and both work fine as a set, so what do you think it is? does anyone have any solutions? I thank anyone who is willing to help.

Yes, a second call to accept() for a particular event name will override the first one. Could you make a function that calls both base.touch() and base.tap(), and add that function in the accept() handler ?

I can, but I would have to rewrite a lot of code because the functions differ way too much, as one is used to help a moving object act, while the other plays out a generalized effect, I guess I don’t have a choice huh?

Anyway, thanks rdb, your quick response solved my issue.

I’m not sure if this will help, but you can accept the same event multiple times if you use different DirectObject instances. The reason that base.accept works is that ShowBase inherits from DirectObject, but you can actually have any class inherit from DirectObject or create any custom instance of it.

If the two accept calls are meant for two logically distinct things (as you seem to describe), then it might make sense to have two separate DirectObject instances to handle each type of event, which would allow you to accept the same event twice.

how would I do that? and is there a way to link it back to the showcase?

Edit: well, I just went with your original idea rdb, and fused the two functions into one, it was actually more straightforward then I described, so thanks, the issue is solved (still).

For future reference, you could do something like:

base.touchEventHandler = DirectObject()
base.tapEventHandler = DirectObject()

base.touchEventHandler.accept('player-again-object', self.touch)
base.tapEventHandler.accept('player-again-object', self.tap)

Of course, you’d ideally call them something more descriptive or work them into your class inheritance hierarchy.

hmm… it looks like something I can use in the future, thanks