Why is the MaskBit maxed out

Posted by CStreel on Game Development See other posts from Game Development or by CStreel
Published on 2012-07-16T09:17:35Z Indexed on 2012/09/15 9:51 UTC
Read the original article Hit count: 184

Filed under:
|
|

Hi there for some reason the maskbit of my b2FixtureDef is being maxxed out and im not sure why

Here is the declaration of the items that are used in the game

enum PhysicBits {
    PB_NONE = 0x0000,
    PB_PLAYER = 0x0001,
    PB_PLATFORM = 0x0002
};

Basically what i want is the player to run along a surface is not slow down (i set platform & player friction to 0.0f)

I then setup my Contact Listener to print out the connections (currently only have 1 platform and 1 player)

Player Fixture Def

b2FixtureDef fixtureDef;
fixtureDef.shape = &groundBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
fixtureDef.filter.categoryBits = PB_PLAYER;
fixtureDef.filter.maskBits = PB_PLATFORM;

Platform Fixture Def

b2FixtureDef fixtureDef;
fixtureDef.shape = &groundBox;
fixtureDef.density = 1.0f;
fixtureDef.friction = 0.0f;
fixtureDef.filter.categoryBits = PB_PLATFORM;
fixtureDef.filter.maskBits = PB_PLAYER;

Now correct me if im wrong but these are saying the following:

  • Player Collides with Platform
  • Platform Collides with Player

Here is the printout of the fixtures colliding with each other

********    <-- Indicates new Contact
Platform
ContactA: 2
MaskA: 1
------
Player
ContactB: 1
MaskB: 2
********    <-- Indicates new Contact
Platform
ContactA: 2
MaskA: 1
------
Player
ContactB: 1
MaskB: 65535
********    <-- Indicates new Contact
Platform
ContactA: 1
MaskA: 65535
------
Player
ContactB: 1
MaskB: 65535

Here is where i am confused. On the second & third contact the player maskBit is set to 65535 when it should be 2 and there are 3 contacts when i am sure at most there should only be 2.

I've been trying to figure this out for hours and i can't understand why it is doing this. I would be very grateful is someone could shine some light on this for me

UPDATE: **I printed out the class of the contacting objects. For some reason it seems to do the following:

First Contact: Correct Result.

Second Contact: Player b2Fixture Obtains a new maskBit.

Third Contact: Platform b2Fixture appears to be set to the same as the Player b2Fixture. It would seem I have a memory race condition i think**

© Game Development or respective owner

Related posts about physics

Related posts about cocos2d-iphone