Page 1 of 1
CollisionRuleCalculator
Posted: Tue Aug 02, 2011 12:28 am
by jlongstreet
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.
Re: CollisionRuleCalculator
Posted: Tue Aug 02, 2011 12:38 am
by Norbo
Can I get the Collidables/BroadPhaseEntrys/etc associated with these CollisionRules in order to compare game-side data about them?
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.
2) Per-actor ignore collision lists -- A and B only generate a broadphase pair if (!A.IgnoreList.Contains(B) && !B.IgnoreList.Contains(A))
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.
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.
Re: CollisionRuleCalculator
Posted: Tue Aug 02, 2011 4:45 pm
by jlongstreet
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.
This makes sense, and seems to work perfectly. Thanks!
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.
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.
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.
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.
Thanks for your help.