Decrease a value by 1 (not more), while sensors are overlapping?

Hi guys

I’m testing a collision between two sensors. I’m trying to decrease a value by one when 2 sensors are overlapping.

The problem is, that sometimes the value gets decreased by 2 even tho I’m using “on collision began”.

I’ve tried removing the collision listener when the collision happens, but still the same issue.

I’ve also tried setting a boolean (true/false) but no help.

Any idea how to do decrease a value by 1 (not more) while sensors are overlapping?

Thank you in advance for any help :slight_smile:

Hi @Ninjadoodle,

Is either your sensor or the colliding object a multi-element body? Do you have listeners on both the sensor and the colliding object?

Brent

following brent’s second point - is it a runtime listener, so same for both?  if so, you’re probably get a separate “began” from each sensor’s perspective of the same collision.  (i assume both sensors “survive” the collision?  so the first event didn’t “kill off” the other object?)

if you were to “tag” your objects with some sort of “id”, you might be able to discover “who’s who” during the collision, fe

myFirstSensor.tag = “sensor#1”

mySecondSensor.tag = “sensor#2”

then you could eaily spot if object1/object2 are being reversed as each sensor “sees” its own collision begin.  then potentially set some type of semaphore on the “other sensor” during the first reported collision, so that “other sensor” ignores its next collision (and clears its semaphore for next time, assuming everyone survives)

maybe?

Hi guys

Thank you for the detailed answers! I played around with the code a bit and I think one of the things you’ve mentioned might have fixed the issue :slight_smile:

Hi @Ninjadoodle,

Is either your sensor or the colliding object a multi-element body? Do you have listeners on both the sensor and the colliding object?

Brent

following brent’s second point - is it a runtime listener, so same for both?  if so, you’re probably get a separate “began” from each sensor’s perspective of the same collision.  (i assume both sensors “survive” the collision?  so the first event didn’t “kill off” the other object?)

if you were to “tag” your objects with some sort of “id”, you might be able to discover “who’s who” during the collision, fe

myFirstSensor.tag = “sensor#1”

mySecondSensor.tag = “sensor#2”

then you could eaily spot if object1/object2 are being reversed as each sensor “sees” its own collision begin.  then potentially set some type of semaphore on the “other sensor” during the first reported collision, so that “other sensor” ignores its next collision (and clears its semaphore for next time, assuming everyone survives)

maybe?

Hi guys

Thank you for the detailed answers! I played around with the code a bit and I think one of the things you’ve mentioned might have fixed the issue :slight_smile: