Page 1 of 1

Collision Rules and Ignoring Collisions

Posted: Sun Apr 22, 2012 7:23 pm
by Shadow0144
Hello,

I know there's a bit of a guide on how to use the collision rules to avoid checking some collisions, but I guess I'm still rather confused on how to use it.
Specifically I want to create turrets and place them on our ship. The ship has a collision mesh and the turrets will have spheres. I want to tell the Space to ignore all turret to ship (or just mesh) collisions. I guess I'm a bit confused on how the whole group, personal, and specific system works. I feel like my answer to my problem lies in there somewhere.

Thank you

Re: Collision Rules and Ignoring Collisions

Posted: Sun Apr 22, 2012 8:36 pm
by Norbo
It sounds like the most direct and easy solution for that situation is to just define a specific rule between the objects.

Doing this for each turret would do the trick:

Code: Select all

CollisionRules.AddRule(ship, turret, CollisionRules.NoBroadPhase);
NoBroadPhase means the ship and turret will not generate a broad phase pair, so no other processing will occur. That method is just a convenience method which adds an entry to the entity.CollisionInformation.CollisionRules.Specific dictionary.

By the way, it may help to note that there is nothing really fundamental about the way the collision rules are set up. It's just a generally helpful hierarchical organization for interaction management. You can define any interaction filtering you want by setting the CollisionRules.CollisionRuleCalculator.

Re: Collision Rules and Ignoring Collisions

Posted: Tue Apr 24, 2012 9:27 pm
by Shadow0144
I'm only using the Sphere, Box (well, not actually using it, but I do have it in the engine), and MobileMesh and they don't seem to have a CollisionRules.AddRule. I can find a

Code: Select all

((Sphere)detectionSphere.getPhysicsCollider()).CollisionInformation.CollisionRules.Specific.Add()
but it doesn't seem to take anything I recognize.

I imagine the

Code: Select all

CollisionRules.AddRule(ship, turret, CollisionRules.NoBroadPhase);
is a member of a different class like Entity, right?

Re: Collision Rules and Ignoring Collisions

Posted: Tue Apr 24, 2012 9:36 pm
by Norbo
CollisionRules.AddRule is a static method. If it's not recognized, add the BEPUphysics.CollisionRuleManagement namespace to your using statements (right clicking->resolve->selecting the desired option will do this for you).

It's a very thin convenience method which interacts with the entity.CollisionInformation.CollisionRules.Specific dictionary. The Specific dictionary contains references to other CollisionRules objects, so the source of the AddRule method is just:

Code: Select all

ownerA.CollisionRules.specific.Add(ownerB.CollisionRules, rule);
where ownerA and ownerB are ICollisionRulesOwner objects. An EntityCollidable is an ICollisionRulesOwner, and by virtue of an entity owning an EntityCollidable, an Entity is also an ICollisionRulesOwner. That is why you can pass the Entity right into the AddRule method.

There's also overloads of the AddRule convenience method which take one ICollisionRulesOwner and another CollisionRules instance.

Re: Collision Rules and Ignoring Collisions

Posted: Fri Jun 23, 2017 9:51 am
by Nablablan
Hi, i am using it

Code: Select all

 CollisionRules.AddRule(SelectedItem.Entity, StickingInto.Entity,CollisionRule.NoBroadPhase);
However, the two guys still collide.

is there something that can go wrong?
One is a compound shape of primitive boxes the other a convex hull shape
i am using an older version as of yet (bc no monogame yet)
has there been a bug?

Re: Collision Rules and Ignoring Collisions

Posted: Fri Jun 23, 2017 5:43 pm
by Norbo
I can't reproduce it in the demos. I don't remember fixing any collision rule related bugs within the last few years, but there may have been one.

Could you try reproducing it in the demos so I can take a closer look?

Re: Collision Rules and Ignoring Collisions

Posted: Sun Jun 25, 2017 4:39 am
by mcmonkey
Nablablan wrote: Fri Jun 23, 2017 9:51 am Hi, i am using it

Code: Select all

 CollisionRules.AddRule(SelectedItem.Entity, StickingInto.Entity,CollisionRule.NoBroadPhase);
However, the two guys still collide.

is there something that can go wrong?
One is a compound shape of primitive boxes the other a convex hull shape
i am using an older version as of yet (bc no monogame yet)
has there been a bug?
Based on what I've tried in the past, I think you have to define it /both/ ways. Meaning:
AddRule(a, b, x);
AddRule(b, a, x);

Not sure if that's correct/intended but it's what I ended up having to do at some point.

Re: Collision Rules and Ignoring Collisions

Posted: Sun Jun 25, 2017 7:11 pm
by Norbo
It shouldn't be necessary to define it both ways when using the default collision rule calculator; it explicitly checks both specific dictionaries: https://github.com/bepu/bepuphysics1/bl ... es.cs#L265

Re: Collision Rules and Ignoring Collisions

Posted: Tue Jun 27, 2017 5:54 pm
by Nablablan
Norbo wrote: Sun Jun 25, 2017 7:11 pm the default collision rule calculator
what is the default collision rule calculator ?
Do I have to do something to enable it (or the collision rules)?

Re: Collision Rules and Ignoring Collisions

Posted: Tue Jun 27, 2017 7:44 pm
by Norbo
The default collision rule calculator, CollisionRules.GetCollisionRuleDefault, is assigned to the CollisionRules.CollisionRuleCalculator at initialization:
https://github.com/bepu/bepuphysics1/bl ... es.cs#L180

So you don't have to do anything special to turn it on.