How to make a CollisionGroup not collide with itself?
How to make a CollisionGroup not collide with itself?
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?
Re: How to make a CollisionGroup not collide with itself?
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:
Note that setting setting the CollisionRules' Personal rule will override the CollisionGroup-defined rule.
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.
Re: How to make a CollisionGroup not collide with itself?
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.
Re: How to make a CollisionGroup not collide with itself?
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.
Re: How to make a CollisionGroup not collide with itself?
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.