Collision Rules and Ignoring Collisions

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Shadow0144
Posts: 14
Joined: Sat Mar 24, 2012 3:22 am

Collision Rules and Ignoring Collisions

Post 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
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Rules and Ignoring Collisions

Post 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.
Shadow0144
Posts: 14
Joined: Sat Mar 24, 2012 3:22 am

Re: Collision Rules and Ignoring Collisions

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Rules and Ignoring Collisions

Post 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.
Nablablan
Posts: 9
Joined: Fri Jun 23, 2017 9:46 am

Re: Collision Rules and Ignoring Collisions

Post 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?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Rules and Ignoring Collisions

Post 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?
mcmonkey
Posts: 92
Joined: Fri Apr 17, 2015 11:42 pm

Re: Collision Rules and Ignoring Collisions

Post 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.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Rules and Ignoring Collisions

Post 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
Nablablan
Posts: 9
Joined: Fri Jun 23, 2017 9:46 am

Re: Collision Rules and Ignoring Collisions

Post 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)?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Collision Rules and Ignoring Collisions

Post 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.
Post Reply