I'm trying to implement a different collision-filtering system with these basic features:
1) CollisionGroups and CollisionMasks -- A and B only generate a broadphase pair if (A.Group & B.Mask && B.Group & A.Mask).
2) Per-actor ignore collision lists -- A and B only generate a broadphase pair if (!A.IgnoreList.Contains(B) && !B.IgnoreList.Contains(A))
I found mention of the CollisionRuleCalculator delegate in the documentation, but it takes two CollisionRules arguments. Can I get the Collidables/BroadPhaseEntrys/etc associated with these CollisionRules in order to compare game-side data about them?
Otherwise, I should be able to accomplish the same thing by modifying the CollisionRules in a CreatingPair handler, but it seems simpler to override CollisionRuleCalculator.
CollisionRuleCalculator
Re: CollisionRuleCalculator
There's nothing in the engine specifically geared towards supporting that, but the CollisionRules class can be extended. Including some data reference in a subclass would provide the necessary information to the delegate with some casting.Can I get the Collidables/BroadPhaseEntrys/etc associated with these CollisionRules in order to compare game-side data about them?
At a glance, it appears this functionality is already covered by the Specific dictionary within every CollisionRules instance. If you wanted to, you could use the CollisionRules class's static methods that are used in the default implementation, like GetSpecificCollisionRuleDefault.2) Per-actor ignore collision lists -- A and B only generate a broadphase pair if (!A.IgnoreList.Contains(B) && !B.IgnoreList.Contains(A))
Technically, the existing CollisionGroup system can also handle requirement 1, but I could see creating a custom solution being a bit easier if the project is ported from something that used collision masks originally or has a specific configuration where there would end up being lots of CollisionGroups.
-
- Posts: 8
- Joined: Mon Jul 04, 2011 8:00 pm
Re: CollisionRuleCalculator
This makes sense, and seems to work perfectly. Thanks!Norbo wrote: There's nothing in the engine specifically geared towards supporting that, but the CollisionRules class can be extended. Including some data reference in a subclass would provide the necessary information to the delegate with some casting.
Yeah, I think this would be possible, but if possible I'd like to stick to something that looks like the design of the original game. Fewer differences means less code to change.At a glance, it appears this functionality is already covered by the Specific dictionary within every CollisionRules instance. If you wanted to, you could use the CollisionRules class's static methods that are used in the default implementation, like GetSpecificCollisionRuleDefault.
Currently, I'm using the existing CollisionRules system to do this, just by adding a NoBroadPhase rule for each pair that doesn't match groups/masks. It works fine, but in the course of adding in the ignore lists, I figured it would be simpler to put it all in one place.Technically, the existing CollisionGroup system can also handle requirement 1, but I could see creating a custom solution being a bit easier if the project is ported from something that used collision masks originally or has a specific configuration where there would end up being lots of CollisionGroups.
Thanks for your help.