confused about sensor contacts

I'm trying to model a ramp in a pinball game, by adding an extra downward force while a ball is on the ramp. The interior poly fixture of the ramp is set as a sensor, but I'm having troubles detecting continuous contacts throughout the steps while the ball is in contact with the ramp.

PostSolve appears to return no contacts at all, and BeginContact only seems to return a single contact on ramp entry.

Is there anything via the contact listener (or something else) that will fire every frame that the ball is in contact with the ramp sensor?

Or do I need to set a flag somewhere, clear it in EndContact, and then do the force processing somewhere else (like my Main ENTER_FRAME) while the flag is set?

--
John
Yes, BeginContact only happens once, that's why it's called 'begin'. Your code is supposed to set some status somewhere and keep it until you get an EndContact for the same sensor. Basically just what you said in the last line there.....
irresistible force wrote:
BeginContact only happens once, that's why it's called 'begin'.

For the record, that's why I tried PostSolve and PreSolve first, but they don't generate contacts for sensors. And it's why I'm looking for (and asking about) any alternatives. Previous Box2D versions had 'Persist()', and so I thought internally the engine probably knows that the objects are still in contact.

The status flag might work, (in fact, I currently have it implemented that way), but if the EndContact event is ever missed, then my ball will continue to think it's on the ramp, and the simulation will be unplayable. I'm sure you've experienced 'stuck' states due to code bugs or missed events somewhere in your life. So hopefully you can understand my desire to ask whether there's a better alternative.

One possibility seems to be not using a sensor, detect in the PreSolve(), and then SetEnabled(false) to ignore the collision. The problem here, is that PreSolve() is fired before the collision occurs (and I think in some cases, when a real collision won't actually occur), so it might generate some ramp force when it shouldn't be there yet.

Still hoping for alternatives, but if there aren't any good ones, I'll accept that the Begin/End status flag is the intended mechanism.
I'd still say that the BeginContact/EndContact and flag-setting is the intended way to handle cases like this. If you are worried that EndContact might not come, then this would be a bug in Box2D and one that would have been seen by hundreds of people already if it did exist. Even then, I would think you'd be equally worried about BeginContact not happening too?

The idea of using a real object when what you want is a sensor goes against the whole point of having sensors and makes more work for you and the physics library as well. Try doing it like you said in your first post and let us know if the EndContact doesn't happen 😉
irresistible force wrote:
I'd still say that the BeginContact/EndContact and flag-setting is the intended way to handle cases like this.
Agreed. I found the "2.1a Update Notes", which clearly states that those are "the only events raised by sensors."

It's not ideal for what I wanted to do, but I'll deal with it. I would have much rather applied the forces to the objects in the listener, when I already had references to the objects right there, as opposed to having to cache those pointers for handling elsewhere.

Quote:
If you are worried that EndContact might not come, then this would be a bug in Box2D and one that would have been seen by hundreds of people already if it did exist.
This is simply untrue. I've uncovered into a number of bugs in the past 30 years, both software and hardware, where other people had made the same claim. Obscure cases happen, simply because the number of variables is nearly infinite. Also, rare bugs can go unnoticed either because the code isn't reliant on that particular feature when an anomaly happens, or because the behavior gets blamed on something else, or because the person who actually observes the bug (an end user) doesn't report it to the developer.

Granted, it's certainly more likely that I'm worrying for nothing. I don't know the internal implementation, and perhaps Box2D is guaranteed to never miss this event. (Or to pick it up on a subsequent frame if it missed the exact moment).

Quote:
Even then, I would think you'd be equally worried about BeginContact not happening too?
Quite the contrary, a missed BeginContact won't result in a stuck state, nor would it break the simulation (in my case).

Quote:
Try doing it like you said in your first post and let us know if the EndContact doesn't happen 😉
The reality of it all, is that were such a missed contact to happen, I'm not going to be the one to see it. So I'll never find out about it, and thus, I won't be able to let you know. 😉

In any case, I'm forging ahead, and thanks for your help.

Original thread: https://box2d.org/forum/viewtopic.php?t=5721