GetContactList stop reporting collisions on welded bodies

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
henriquenj
Posts: 2
Joined: Mon Sep 17, 2012 9:56 am

GetContactList stop reporting collisions on welded bodies

Postby henriquenj » Mon Sep 17, 2012 10:04 am

Hi guys, I have some strange problem with my game which uses Box2D as physics engine and I'm out of ideas on what I can do to solve it.

My game is a class assignment where I need to build a simple game where the main character moves in a 2D environment while square blocks comes from below him. Each time a collision occurs, that block is attached to the character using a weld joint, when three blocks of the same colors are together, they annihilate themselves(an effect similar to Bejeweled). I'm using a recursive function to iterate through all the attached blocks of a given block to see if there are enough blocks for them to be deleted.

I'm using GetContactList function to iterate through the list of contacts to see which blocks are adjacent to each other. The results are quite disappointing, the blocks only get annihilated in few cases. After a lot of debugging, I found the issue, but I still don't know how to solve.

My issue is: after some time, GetContactList STOPS returning contacts (return NULL) to blocks that were already attached for some time . I spent some time reading the Box2D manual as well as some tutorials and still didn't find any clue of what is happening.

Below there's some simplified version of the code that I wrote.

Code: Select all

for(int a = 0; a < blocksList.size(); a++)
{
      blocksList[a].BuildConnections();
}


And on BuildConnections

Code: Select all

    b2ContactEdge* edge = body->GetContactList();
    while(edge != NULL)
    {
       if (long_check_to_see_if_there's_a_block_nearby)
       {
           //if there's, call BuildConnections again on the adjacent block
           adjacentBody->GetUserData()->BuildConnections;
       }
       edge = edge->next;
    }


I know that there's another issue related to circular inclusions, but I fairly sure that this problem isn't causing the problem with the collisions.

You can download my entire code from this page if you'd like http://code.google.com/p/fellz/source/list

irresistible force
Posts: 1988
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: GetContactList stop reporting collisions on welded bodie

Postby irresistible force » Mon Sep 17, 2012 6:23 pm

Joints have a collideConnected property which is usually set to false by default, so that any collisions between the two joined bodies are ignored. Maybe you just need to set this to true.

henriquenj
Posts: 2
Joined: Mon Sep 17, 2012 9:56 am

Re: GetContactList stop reporting collisions on welded bodie

Postby henriquenj » Wed Sep 19, 2012 5:37 am

I just tried this and works perfectly now! Thank you very much for your information. I was suspecting that the issue was caused by some little detail of Box2D that I simply ignored so far.

My work can continue now.


Return to “General Discussion”



Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot], Exabot [Bot], Google [Bot] and 1 guest