Box2D Forums

It is currently Sun May 19, 2013 7:35 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Sun May 20, 2012 12:14 pm 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
Hello, what I'm trying to achieve is:

By default body is STATIC, after contact with my 2nd body, I'm changing first body type to DYNAMIC.

But I would also like to disable possibility to collide with different bodies after this process, so it would just simply fall on the ground.

I know I can create body which won't collide or will collide only with certain bodies by creating special fixture def, but I have to disable colliding after contact between two bodies.

Thanks in advance for help!


Top
 Profile  
 
PostPosted: Sun May 20, 2012 4:17 pm 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
You can get the fixtures' filter data (even after fixture and body creation) and change the mask bits so it won't collide with other stuff.


Top
 Profile  
 
PostPosted: Mon May 21, 2012 1:33 am 
Offline

Joined: Fri Oct 07, 2011 9:39 am
Posts: 21
Hey, thanks for reply. I'm making android game, that's why I'm trying to avoid creating new objects at runtime.

That's inside my contact listener (executed after contact with player)

Code:
final Fixture x1 = contact.getFixtureA();

if (contact between my player's head fixture and box)
{
       x1.getBody().getFixtureList().get(0).getFilterData().maskBits = 0x0001;
       // and so on to set rest of shorts
}


But really I can't get how to set those shorts, to make body not collide able with anything (even with the same body type, and that's my main problem now)

// Edit1: I'm stupid, so I will create at beginning Filer object with my bits and than just will set this filter

Code:
                     Filter f = new Filter();
                     f.categoryBits =
                                                        ...                     
                     x1.getBody().getFixtureList().get(0).setFilter(f);


But still the problem is how to set those shorts, to prevent from collision with anything (Even same type bodies)

// Edit2: That configuration works if anyone will need it:

Code:
      boxBreakFilter = new Filter();
      boxBreakFilter.categoryBits = 1;
      boxBreakFilter.groupIndex = 2;
      boxBreakFilter.maskBits = (short)0;


And than just set this filter on your fixture, and it isn't colliding with anything, even with same body types.

Thanks for help - problem SOLVED.


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 3 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