having trouble with filters

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
ff7squirrelman
Posts: 4
Joined: Sat Mar 07, 2015 11:08 am

having trouble with filters

Postby ff7squirrelman » Wed Dec 20, 2017 3:02 am

ok, so first off i'm using the box2d that comes with LIBGDX so I think it uses a java wrapper or something like that. I have been using collision filters without a problem until I tried adding a body that would collide with itself and the level only. I've tried several combinations but I guess i'm just not understanding it right.

So I have moneyBag - should collide with itself and the level (though I would like to know how to make it only collide with the level and not itself as well in case I change it).
the level - collides with basically everything
enemies - collide with allies and the level
allies -collide with enemies and the level

I have this currently:

Code: Select all

public static final short CATEGORY_ENEMY = -0x2;
public static final short CATEGORY_ALLY = -0x4;
public static final short CATEGORY_SENSOR = -0x8;
public static final short CATEGORY_BODY = -0x20;
public static final short CATEGORY_LEVEL = 0x40;
public static final short CATEGORY_GOLDBAG = 0x80;


level filter settings:

Code: Select all

    fixtureDef.filter.categoryBits = GameWorld.CATEGORY_LEVEL;


allies filter settings:
main body

Code: Select all

    fixtureDef.filter.categoryBits = GameWorld.CATEGORY_ALLY;
    fixtureDef.filter.groupIndex = GameWorld.CATEGORY_ALLY;

attack body (used to see when enemies are in attack range)

Code: Select all

    fixtureDef.filter.categoryBits = GameWorld.CATEGORY_ALLY;
    fixtureDef.filter.maskBits = GameWorld.CATEGORY_ENEMY;
    fixtureDef.filter.groupIndex = GameWorld.CATEGORY_SENSOR;


enemy filter settings:
main body

Code: Select all

        fixtureDef.filter.categoryBits = GameWorld.CATEGORY_ENEMY;
        fixtureDef.filter.groupIndex = GameWorld.CATEGORY_ENEMY;

attack body (used to see when allies are in attack range)

Code: Select all

        fixtureDef.filter.categoryBits = GameWorld.CATEGORY_ENEMY;
        fixtureDef.filter.maskBits = GameWorld.CATEGORY_ALLY;
        fixtureDef.filter.groupIndex = GameWorld.CATEGORY_SENSOR;


money bag filter settings:

Code: Select all

        fixtureDef.filter.categoryBits = GameWorld.CATEGORY_GOLDBAG;
        fixtureDef.filter.maskBits = GameWorld.CATEGORY_LEVEL;
        fixtureDef.filter.groupIndex = GameWorld.CATEGORY_GOLDBAG;

I also tried this for money bags (I forget the other tries)

Code: Select all

        fixtureDef.filter.categoryBits = GameWorld.CATEGORY_GOLDBAG;
        fixtureDef.filter.maskBits = GameWorld.CATEGORY_LEVEL | GameWorld.CATEGORY_GOLDBAG;


everything works right except that the money bags collide with everything, I tested several different filter settings and none seemed to work without causing issues with other things. I was under the impression that setting their mask to a positive value would only let them collide with other bodies with the same mask value. Any idea what I am doing wrong?

ff7squirrelman
Posts: 4
Joined: Sat Mar 07, 2015 11:08 am

Re: having trouble with filters

Postby ff7squirrelman » Wed Dec 20, 2017 12:24 pm

I need to test it more to be sure but I made the following changes and it "seems" to be working right now, at least at first glance.

Code: Select all

public static final short CATEGORY_ENEMY = -0x0002;
public static final short CATEGORY_ALLY = -0x0004;
public static final short CATEGORY_SENSOR = -0x0008;
public static final short CATEGORY_BODY = -0x0020;
public static final short CATEGORY_LEVEL = 0x0040;
public static final short CATEGORY_GOLDBAG = 0x0080;


level

Code: Select all

fixtureDef.filter.categoryBits = GameWorld.CATEGORY_LEVEL;
fixtureDef.filter.groupIndex = GameWorld.CATEGORY_LEVEL;


moneybags

Code: Select all

fixtureDef.filter.categoryBits = GameWorld.CATEGORY_GOLDBAG;
fixtureDef.filter.maskBits = 0;
fixtureDef.filter.groupIndex = GameWorld.CATEGORY_LEVEL;


Return to “General Discussion”



Who is online

Users browsing this forum: No registered users and 5 guests