Can't get event OnCollision to fire on last geom in chain

Jan 5, 2009 at 9:18 PM
I'm trying to set the OnCollision event only on the last Geom in this chain. It's not working, if I remove the "if" and set the OnCollision event on every Geom then the event gets called, is this a bug or should it be like this?
(the CollisionCategories also don't seem to work to only set to some of them, I have to set all of them)

for (int i = 0; i < _chain.Geoms.Count; i++ )
{
  _chain.Geoms[i].CollisionCategories = CollisionCategory.Cat2;
  _chain.Geoms[i].CollidesWith = CollisionCategory.All & ~CollisionCategory.Cat1 & ~CollisionCategory.Cat2 & ~CollisionCategory.Cat4 & ~CollisionCategory.Cat5;
              
  if (i == (_chain.Geoms.Count - 1))
  {
     _chain.Geoms[i].OnCollision += OnRopeCollision;
  }
}

Thanks
Coordinator
Jan 5, 2009 at 10:26 PM
Can't seem to see the problem with the OnCollision event.

Try a simple _chain.Geoms[_chain.Geoms.Count -1].OnCollision to see if that solves your problem. Is it BTW the chain from the demos?

As for the CollisionCategories, you should ether use CollisionGroup or CollisionCategory & CollidesWith. They are 2 sides of the same system, but CollisionCategories enables a more flexable system. They are not as easy to use as CollisionGroup though.

The default CollisionCategory for both CollisionCategories and CollidesWith is CollisionCategory.All, if you want any other behavior, you will need to specify it on all geometries.
Jan 5, 2009 at 11:50 PM
Tried with _chain.Geoms[_chain.Geoms.Count -1].OnCollision but same result, yes it's from the advanced demo, I moved it to my own project but the code is almost the same.
Coordinator
Jan 6, 2009 at 12:46 AM
Oh, it seems that CreateGeom() is called after the creation of the chains inside demo5. Just remove the call and you should be ready to go.
Thanks for spotting that.
Jan 6, 2009 at 11:01 AM
Yes that made it work, thanks