How to make a CollisionGroup not collide with itself?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Sigil
Posts: 6
Joined: Fri Jun 18, 2010 8:06 pm

How to make a CollisionGroup not collide with itself?

Post by Sigil »

Let's say I have a pool of 100 bullets, all with the same collision group. How do I set those up to totally ignore each other in the collision rules? I tried CollisionGroupRules.Add( new CollisionGroupPair( bulletGroup, bulletGroup ), CollisionRule.NoPair ) but the bullets are still happily colliding with one another. What am I doing wrong here? Surely I don't have to individually add specific collision rules for the other 99 bullets in the pool to each bullet in the pool, do I?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to make a CollisionGroup not collide with itself?

Post by Norbo »

That should work. If every bullet is given that same CollisionGroup and that CollisionGroup has a rule with itself of NoPair, then they should not collide:

Code: Select all

CollisionGroup noSelfCollideGroup = new CollisionGroup();
Space.SimulationSettings.CollisionDetection.CollisionGroupRules.Add(new CollisionGroupPair(noSelfCollideGroup, noSelfCollideGroup), CollisionRule.NoPair);

... For every bullet...
bullet.CollisionRules.Group = noSelfCollideGroup;

Note that setting setting the CollisionRules' Personal rule will override the CollisionGroup-defined rule.
Sigil
Posts: 6
Joined: Fri Jun 18, 2010 8:06 pm

Re: How to make a CollisionGroup not collide with itself?

Post by Sigil »

Oh, that's what it is. I had them set to NoResponse for their .Personal rule, so they wouldn't physically affect their targets from the collision. Thanks.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to make a CollisionGroup not collide with itself?

Post by Norbo »

By the way, if you find an awkward situation where it would be really nice if the collision rules were calculated a little differently, you can change the BroadPhase's CalculateCollisionRuleCallback. It defaults to the EntityCollisionRules.GetCollisionRule method, and you can use some of the EntityCollisionRules static methods to help compute custom rules if you find the need.
Sigil
Posts: 6
Joined: Fri Jun 18, 2010 8:06 pm

Re: How to make a CollisionGroup not collide with itself?

Post by Sigil »

That's good to know, thanks. I have not been focusing on physics until recently, so I'm still learning some of the quirks of this engine.
Post Reply