CollisionRules.Specific syntax
CollisionRules.Specific syntax
Hello! I'm a bit confused as to CollisionRules.Specific. Here is my situation: I have lots of different objects in my environment and I would like to have most objects not do a broadphase with a specific static object. However, there is a group of spheres that I do want to collide with the object. I tried to set the CollisionRules.Personal to noBroadphase and then add a specific rule for any item under this CollisionGroup but I'm having trouble figuring out the syntax for adding a rule to an item's CollisionRules.Specific. Also, if there is a better way to do this, I would love to hear it. Thanks!
Re: CollisionRules.Specific syntax
The easiest way to manage Specific rules is the CollisionRules helper method. Instead of having to search for the collision rules instance, you can give the CollisionRules.AddRule method the entities (or anything that has collision rules) involved and specify the rule between them:
It sounds like using CollisionGroups might be the easiest option for your situation. By the description, there would be three collision groups, with rules in between them. Here's a sample implementation:
Note that the above uses a development version that I'm about to post up on codeplex in a minute or two (http://bepuphysics.codeplex.com/SourceC ... evelopment). In older versions, you had to specify a Space for the collision group methods, which was technically unnecessary and internally unused in v0.15.0+. If you don't want to upgrade, you can safely pass in null to those methods for the space.
Edit: the development version has been uploaded.
Code: Select all
CollisionRules.AddRule(entityA, entityB, CollisionRule.NoBroadPhase);
Code: Select all
var sphereGroup1 = new CollisionGroup();
var sphereGroup2 = new CollisionGroup();
var staticObjectGroup = new CollisionGroup(); //If you had multiple such static objects, this could be given to all of them.
CollisionGroup.DefineCollisionRule(sphereGroup1, staticObjectGroup, CollisionRule.NoBroadPhase); //Group 1 doesn't collide with the special static object group.
//The DefaultKinematicCollisionGroup has a rule with itself that prevents collision.
//Since the interaction between collision groups defaults to normal, which would result in collision between the special static objects and other kinematic objects,
//add the rule for the staticObjectGroup too.
CollisionGroup.DefineCollisionRule(staticObjectGroup, CollisionRules.DefaultKinematicCollisionGroup, CollisionRule.NoBroadPhase);
//Assign the relevant objects to the approrpiate collision groups.
aGroup1Sphere.CollisionInformation.CollisionRules.Group = sphereGroup1;
//and so on.
Edit: the development version has been uploaded.
Re: CollisionRules.Specific syntax
Thanks for the reply. I was able to get the
CollisionGroup.DefineCollisionRule(sphereGroup1, staticObjectGroup, CollisionRule.NoBroadPhase);
concept to work. I thought about using groups but that would require me to remember to set the group for every new item I make from now until the end of my project and that is not something I would be likely to remember. Thanks again!
CollisionGroup.DefineCollisionRule(sphereGroup1, staticObjectGroup, CollisionRule.NoBroadPhase);
concept to work. I thought about using groups but that would require me to remember to set the group for every new item I make from now until the end of my project and that is not something I would be likely to remember. Thanks again!