How to stop object from registering two collisions instead of one? (better explanation in post)

Basically my wall is built up of segments and if you hit it perfectly in the middle it registers as a collision on both walls. Which really messes up my scoring algorithm and some other things in my game, Is there a way to prevent multi-collisions?  

Could you give the object a “.hasCollided” property, and then set that to true on the first collision? Then in your collision code use:

if obj.hasCollided == false then obj.hasCollided = true --do your collision stuff end

The problem is that it isn’t a one time collision, I have an object that is bouncing inside walls. I just need to stop it from triggering two collisions when the ball hits in directly in between two segments

Then how about:

if obj.hasCollided == false then obj.hasCollided = true --do your collision stuff timer.performWithDelay(1, function() obj.hasCollided = false end, 1) end

That should force the bool back to false in the next frame. It’s still not perfect by any means, but perhaps you can modify it to suit your needs.

Hi @puppymodz,

The suggestion by @AlanPlantPot is good. Also, make sure that you “return true” at the end of your collision listener, so it doesn’t propagate to other collisions… just a fail-safe in that regard.

Brent

Could you give the object a “.hasCollided” property, and then set that to true on the first collision? Then in your collision code use:

if obj.hasCollided == false then obj.hasCollided = true --do your collision stuff end

The problem is that it isn’t a one time collision, I have an object that is bouncing inside walls. I just need to stop it from triggering two collisions when the ball hits in directly in between two segments

Then how about:

if obj.hasCollided == false then obj.hasCollided = true --do your collision stuff timer.performWithDelay(1, function() obj.hasCollided = false end, 1) end

That should force the bool back to false in the next frame. It’s still not perfect by any means, but perhaps you can modify it to suit your needs.

Hi @puppymodz,

The suggestion by @AlanPlantPot is good. Also, make sure that you “return true” at the end of your collision listener, so it doesn’t propagate to other collisions… just a fail-safe in that regard.

Brent