GetContactList stops reporting collisions on welded bodies
Posted
by
Henrique Jung
on Game Development
See other posts from Game Development
or by Henrique Jung
Published on 2012-09-12T22:29:55Z
Indexed on
2012/09/13
3:52 UTC
Read the original article
Hit count: 347
box2d
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.
for(int a = 0; a < blocksList.size(); a++)
{
blocksList[a].BuildConnections();
}
And on BuildConnections
b2ContactEdge* edge = body->GetContactList();
while(edge != NULL)
{
if (long_check_to_see_if_there's_a_block_nearby)
{
// add itself to the list to be anihilated
globalList.push_back(this);
//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
© Game Development or respective owner