Collision between shapes and a body

Hi there!
This may be a very stupid question, but I just couldn't solve that problem I have myself.

What I have is a compund object, something like a maze. In this maze there are little dots, like cookies, which are shapes of the maze aswell. The whole maze is static. Now there's a dynamic body in this maze and I have to check collisions between this body and these "cookie"-shapes of the maze. If there is a collision I want to destroy the "cookie"-shape.

I tried changing the b2ContactListener-class as it worked for me in another small project, but somehow it seems like the collisions between my bodies and shapes aren't detected. I feel a bit confused now... 😢

Well, I don't know how I should check collisions between this body and these "cookie"-shapes, maybe the answer is an easy one.

I'd appreciate any help! 😀

AgentGrautvornix
How were you doing collision detection in your other project? Event listeners? Or object boolean? There are two methods for CD, but there shouldn't be much trouble implementing either of them so that your dynamic object (I'm assuming player) can eat the cookies.

Check this tutorial out if you're struggling, he's got a lot of code in there:

http://blog.allanbishop.com/box2d-2-1a- ... detection/

There's also a follow up in one of the comments which allows you to clean up the code heaps and use an object instead of Event Listeners as event listeners are pretty heavy and not really necessary for CD if it's going to be happening every two seconds.

SC
Thanks, I knew this b2ContactListener method and read this tutorial already, but I forgot to set the contactlistener for the world! 😆

After adding these two lines it worked! 😀
And I didn't use eventlisteners but set the userData.remove to true and then checked this boolean in the update function, works all fine.

Thank you!
I don't know if you have this issue (I did), but I will also recommend you make these "cookies" sensors instead of static bodies. I have "coins" that I pick up in my platformer game, and everytime I collided with one, my player would move back, responding to the collision, the "coin" was destroy next frame, and the player would keep moving, which as you can tell looks weird. Sensons help this issue.

Hope it helps.

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