Calculate the Collision Location

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Calculate the Collision Location

Post by ChillyFlashER »

Image

So lets say the Players Collide under the box how would I calculate so I know what side of the Object it is colliding with?
And if it is ontop, sides etc. But how would I get this information?
I just don't know what Collision Information Event I should use, what I should calculate, to get the right information.

Sorry for my bad explanation I have tried to get this working for some hours now, but no results.
Getting just tired and annoyed, I just cant think anymore...

Regards Eric.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

Using Events is not always the easiest way to analyze collisions. It may be more convenient just to scan through the entity.CollisionInformation.Pairs list and go through each pair's Contacts list.

Each contact has position, normal, depth, and some other stuff. The collision side can be found using the contact normal. The process would look like this:

1) Calibrate the normal. The normal may be negated from what you expect depending on the pair configuration. Compute the offset from the reference entity (can be either object in the pair, so long as it's done consistently) position to the contact position. Dot the contact normal against the offset. If it's positive, then the normal points away from the reference entity. If it's negative, the normal points towards the reference entity. Pick either 'away' or 'towards' as a convention and use it to calibrate the normals consistently. If it's pointing away and you want to to point towards or vice versa, negate the normal. This process assumes that the reference entity is convex.

2) Find the test entity's face which most closely matches the calibrated normal. For a box, this is fairly easy- dot the three axes of the rotation matrix against the normal and pick the one largest in magnitude. The sign of this dot product tells you which face along the tested axis the normal is closest to.
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Re: Calculate the Collision Location

Post by ChillyFlashER »

When I do this is seems like the static objects collide? Should this happen? If so is there a way to change there collision group rule or something?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

The above should have no effect on whether or not static objects collide.

By default, infinite mass objects (StaticMeshes, InstancedMeshes, Terrains, StaticGroups, and kinematic entities) all have a CollisionGroup, CollisionDetectionSettings.DefaultKinematicCollisionGroup, which cannot produce pairs with itself. If the objects were given another group manually or if the rules were changed otherwise, this might no longer be the case, allowing pairs between infinite mass objects to exist.

Dynamic objects belonging to the CollisionDetectionSettings.DefaultDynamicCollisionGroup create pairs with objects in the DefaultKinematicCollisionGroup by default.

More information about collision rules can be found in the CollisionFilteringDemo in the BEPUphysicsDemos and in the Collision Rules documentation on codeplex.
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Re: Calculate the Collision Location

Post by ChillyFlashER »

If I do something like this it wont work.

Code: Select all

// y , x for-loop
BEPUphysics.Entities.Prefabs.Box box =
     new BEPUphysics.Entities.Prefabs.Box(new Vector3(2 * y, -2 * x, 0), 2, 2, 2);
Space.Add(box);
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

In what way does it not work? What do you expect to see, and what do you see instead?
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Re: Calculate the Collision Location

Post by ChillyFlashER »

I just do that the I foreach all the pairs and I get the other Box'es Collision.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

In isolation, that code will produce a grid of boxes which do not generate collision pairs with each other due to the default collision rules configuration. Is this what you see?

If it is what you see, then what do you want to see instead?

If the above is not what you see, what do you see instead? If collision pairs are generated between the kinematic objects, the collision rules were likely modified in some way away from their default settings.
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Re: Calculate the Collision Location

Post by ChillyFlashER »

I see collision Pairs between the box'es. And I just wan't to see the Player Entities Collision. I have made so it will look at the Entity's Tag if it is a player. But then it wont collide with all the objects.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

I see collision Pairs between the box'es.
If you see collision pairs between kinematic boxes, the collision rules have been modified. Look for any changes to collision rules or collision groups.
And I just wan't to see the Player Entities Collision.
If you only want to check for collisions between the player and the world, then I would recommend only scanning through the playerEntity.CollisionInformation.Pairs list rather than all objects.
But then it wont collide with all the objects.
Scanning and analyzing collisions has no effect on whether or not things actually collide. If collisions are occurring when they shouldn't or aren't occurring when they should, the collision rules aren't configured correctly.
ChillyFlashER
Posts: 6
Joined: Wed Jul 04, 2012 7:17 pm

Re: Calculate the Collision Location

Post by ChillyFlashER »

I managed to make it work with just checking the players Collision Pair's. But when I do box'es like that, will all those be kismetic and not static?

Thanks Allot for all your help!! :D
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Calculate the Collision Location

Post by Norbo »

But when I do box'es like that, will all those be kismetic and not static?
If the question is about the collision rule behaviors: iterating through the collision pairs associated with a dynamic player will find all dynamic, kinematic, or static objects that the player is in collision with. The dynamic player entity's default collision group collides with everything. Only kinematic/static objects start with a collision group which rejects collisions with other kinematic/static objects.

If the question is about whether or not those specific boxes are classified as kinematic or static: they are kinematic. Entities created without mass (or later set to be kinematic) are kinematic because they are still capable of movement by setting their velocity. Technically, it is possible to create a truly 'static' box by putting a ConvexCollidable<BoxShape> into a StaticGroup, but that's an advanced usage.
Post Reply