Collision Rules and Ignoring Collisions
-
- Posts: 14
- Joined: Sat Mar 24, 2012 3:22 am
Collision Rules and Ignoring Collisions
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
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
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:
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.
Doing this for each turret would do the trick:
Code: Select all
CollisionRules.AddRule(ship, turret, CollisionRules.NoBroadPhase);
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.
-
- Posts: 14
- Joined: Sat Mar 24, 2012 3:22 am
Re: Collision Rules and Ignoring Collisions
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
but it doesn't seem to take anything I recognize.
I imagine the
is a member of a different class like Entity, right?
Code: Select all
((Sphere)detectionSphere.getPhysicsCollider()).CollisionInformation.CollisionRules.Specific.Add()
I imagine the
Code: Select all
CollisionRules.AddRule(ship, turret, CollisionRules.NoBroadPhase);
Re: Collision Rules and Ignoring Collisions
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:
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.
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);
There's also overloads of the AddRule convenience method which take one ICollisionRulesOwner and another CollisionRules instance.
Re: Collision Rules and Ignoring Collisions
Hi, i am using it
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?
Code: Select all
CollisionRules.AddRule(SelectedItem.Entity, StickingInto.Entity,CollisionRule.NoBroadPhase);
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
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?
Could you try reproducing it in the demos so I can take a closer look?
Re: Collision Rules and Ignoring Collisions
Based on what I've tried in the past, I think you have to define it /both/ ways. Meaning:Nablablan wrote: ↑Fri Jun 23, 2017 9:51 am Hi, i am using itHowever, the two guys still collide.Code: Select all
CollisionRules.AddRule(SelectedItem.Entity, StickingInto.Entity,CollisionRule.NoBroadPhase);
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?
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
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
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.
https://github.com/bepu/bepuphysics1/bl ... es.cs#L180
So you don't have to do anything special to turn it on.