CollisionGroup not working in WP7 emulator?

Feb 24, 2011 at 5:55 PM


I've been trying to have a set of objects not colliding with each other but with everything else. I've understood that this can be done by setting the same value (not 0) as their PhysicsObjectBehavior's CollisionGroup. I started with the following user control:


    <Canvas x:Name="LayoutRoot" Width="100" Height="100">
        <Ellipse x:Name="Ellipse"  Height="20" Stroke="#FFACB160" Width="20">
                <pb:PhysicsObjectBehavior x:Name="Pob1" IsBullet="False" Mass="0.1" RestitutionCoefficient="1" CollisionGroup="5"/>
                <LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
                    <GradientStop Color="Black"/>
                    <GradientStop Color="#FFED1313" Offset="1"/>


then created two instances dynamically and assumed they'd both be in the same collision group, CollisionGroup == 5.

As they still seemed to collide, i tried to set the collision group manually with: 


                foreach (FrameworkElement element in ellipse1.LayoutRoot.Children)
                    PhysicsObjectMain main = element.GetValue(PhysicsObjectMain.PhysicsObjectProperty) as PhysicsObjectMain;
                    if (main != null)
                        main.CollisionGroup = 5; 

which didn't have effect, either. What actually did work was :

PhysicsSprite sprite = _physicsController.PhysicsObjects["Ellipse"];
foreach (Fixture f in sprite3.BodyObject.FixtureList)
     f.CollisionFilter.CollisionGroup = 5;


which I guess is more of a FPE way of doing things rather than how it should be done when using Physics Helper.

I'm quite certain I'm doing it wrong so it'd be nice if someone could point out my stupidity and maybe even provide a solution. With all the samples from across different versions of Physics Helper and Silverlight, I'd really appreciate a working example, that's using the latest Physics Helper, with two object passing through each other.

Thanks in advance,


Mar 12, 2011 at 6:51 PM

The same thing is happening to me.  I set the collision group on the behavior and it still collides anyway.

Mar 12, 2011 at 8:48 PM

Yep, a bit odd that there are no other comments on this since, i think, it's one of the most basic use cases. Still using the aforementioned workaround. 

Mar 14, 2011 at 8:56 AM
Edited Mar 14, 2011 at 8:56 AM

I think I've seen this in the PH4 beta also for Silverlight too (a least I haven't got it to work). In other words, I don't think it's isloated for WP7, but I might be wrong here.


Mar 23, 2011 at 10:06 AM

I ran into the same problem in SL4.

But the workaround is great, as you can access the CollisionCategories, which are not exposed as properties at all, as well.

Apr 2, 2011 at 9:23 PM

it seems that we need to manually set CollisionFilter.CollidesWith property of sprite's fixture:

foreach (Fixture f in sprite3.BodyObject.FixtureList)
   f.CollisionFilter.CollidesWith = CollisionCategories.All & ~CollisionCategories.Cat5;
* f wont collide with Cat5

Apr 28, 2011 at 10:06 AM

Hi all,

I can't get to the Fixturelist! I have this code:

 FrameworkElement ctl = elem as FrameworkElement;


 PhysicsObjectMain physObject = ctl.GetValue(PhysicsObjectMain.PhysicsObjectProperty) as PhysicsObjectMain; (and yes, this code finds the controls I'd like to set a coliisiongroup on)

And I try to apply the code from the post above (assuming that "sprite3" should be "sprite":

PhysicsSprite sprite = _physicsController.PhysicsObjects["Ellipse"];
foreach (Fixture f in sprite.BodyObject.FixtureList)
     f.CollisionFilter.CollisionGroup = 5;

But when I try to rewrite the code, I only get error messages saying that PhysicObjectMain does not contain a BodyObject:

foreach (Fixture f in physObject.BodyObject.FixtureList)
                            f.CollisionFilter.CollisionGroup = 5;

So what should I write to hook things up?



Apr 29, 2011 at 4:40 AM

what version of physicshelper do you use? it seems there is inconsistency in code (since it is still beta-but of course you can take a look at object browser for class substitution).

i use (it has better performance than the latest

Apr 29, 2011 at 11:58 AM


I'm using the latest version (the one Andy just did an installer for). Why do you ask? I don't think Collisiongroups has worked in any of the PH4 versions, am I wrong?

In any case I don't want to downgrade to earlier versions because of other things that have been fixed. I just need to sort out how to hook this up. :-)



May 1, 2011 at 4:01 AM

collision groups work just fine if you set them manually:

foreach (Fixture f in physicsSprite.BodyObject.FixtureList)
f.CollisionFilter.CollisionGroup = 5;

sorry if thats not answer your question