CollisionGroups not working as intended?

Apr 27, 2011 at 8:41 PM

I've been trying to get some CollisionGroups working today, but there always seem to be some problems that I can't fix. Basically there are multiple layers of the same level, where you can switch around as you want. Some objects are supposed to change the layer with you, but you can't move stuff on a different layer.


First I tried using CollisionGroups, which was not working like I wanted at all. Things just collided all the time, unless I set them to a negative value, where nothing could collide. Then I return the settings value back to normal and tried using CollisionCattegories, which was kinda working after a few hours. BUT i have to recreate the fixtures every time i want the object to switch layer, otherwise it will ignore collisions for a short moment and get stuck in the ground or fall through it.


            if (world == 1)
                f.CollisionFilter.CollisionCategories = Category.Cat3;
                f.CollisionFilter.CollidesWith = Category.Cat3;
                f.CollisionFilter.CollisionCategories = Category.Cat2;
                f.CollisionFilter.CollidesWith = Category.Cat2;


Am i doing something wrong or is there a better way?

Apr 27, 2011 at 9:05 PM

I have never tried switching Collision Categories during a running simulation - I've only done this at the beginning of a level.

You might want to post this to the Farseer forums - I found this related issue but looks like it was resolved and it may have applied to Farseer 2.x anyway -

Apr 28, 2011 at 2:25 PM

Sadly, it seems like that fix was only for the 2.x versions.

Today I've tried using the OnCollision and BeginContact events, but I couldn't find a way to let the physics recheck if the collision would still occur under the new circumstances (other layer). Basically you can jump on a box at the first layer, switch layers and you will keep standing in the air, until you jump (moving to the sides doesn't help).

Apr 28, 2011 at 2:31 PM

I wonder if you need to wake up resting bodies?

It might be worth trying. Just set Awake = true on all bodies after changing collision categories.

Apr 28, 2011 at 9:30 PM

All bodies are awake.

f.Body.Inertia = float.MaxValue; seems to reduce the chance of this problem occuring without me doing anything. It still always happens when I'm jumping on a box that changed the layer with me (kinda looks like stomping it into the ground).


Next thing i tried was using multiple worlds and switch the fixture via world.removebody() and world.addbody(), but it seems to cause problems.