Box2D Forums

It is currently Fri Oct 31, 2014 2:00 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Mon Sep 17, 2012 10:04 am 
Offline

Joined: Mon Sep 17, 2012 9:56 am
Posts: 2
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:
for(int a = 0; a < blocksList.size(); a++)
{
      blocksList[a].BuildConnections();
}


And on BuildConnections

Code:
    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


Top
 Profile  
 
PostPosted: Mon Sep 17, 2012 6:23 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1965
Location: Tokyo
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.


Top
 Profile  
 
PostPosted: Wed Sep 19, 2012 5:37 am 
Offline

Joined: Mon Sep 17, 2012 9:56 am
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group