OnCollison event for geom Vertecies

Mar 15, 2009 at 11:04 PM
Edited Mar 15, 2009 at 11:11 PM
To best explain my problems i have created multiple image files to provide visual reference.
In the following image
a setup of the scene is shown.
  • The dark blue object in the center in the center is the main Body I will call 'Player' which contains a geom for collision purposes. This body will never rotate, it will only stay upright
  • The light blue hexagon object behind the 'Player' will be referred to as the 'Proxy Field'. The 'Proxy Field'  is an object that always follows the 'Player'. The only way i could get this object to follow 'Player' by creating a body for it and every frame relocate to the 'Player' position (if there is a better way of doing this please let me know, perhaps if it's possible to just make the 'Player' body contain two Geoms, a 'Player' geom and a 'Proxy' geom).  There is only collision detection for the 'Proxy Field' via OnCollsion. It will not deflect off any object, only detect if there is a collison.
  • The green area is just the areas the character interacts with, such as floors and walls.
The next image
shows what would happen if gravity is applied. as you can see the 'Player' is sitting above the floor and the 'Proxy' is penetrating through the floor and only there for collision detection.
The areas labeled 'Detection Points' is the problem I'm having. Along with the proxy being able to detect collisions via OnCollsion, I would also like it do return if any and which of the points(vertices) used to create the hexagon are collision. So if the top point was labeled point_1 and each point clockwise is incrementally labeled, the 'Proxy' would return that point_4 is currently colliding.

In the next image
I would want point_2, point_3,  and point_4 to be returned. Along with the OnCollsion detection for the whole 'Proxy' itself.

Any help will be greatly appreciated. Thank you

Mar 16, 2009 at 9:06 AM
I'll take a stab at it, although its going to be the blind leading the blind, lol.  I think what you want to do is create your own OnCollisionMethod.  When you do that, you accept a ContactList (see below), which contains a list of the points which are currently marked as colliding.  You can then get those from your list and do with them what you need.

    yourGeom.OnCollision += MyOnCollisionMethod;

    private bool MyOnCollisionMethod(Geom geom1, Geom geom2, ContactList list) { do stuff }

Also, you can connect your Hex using a joint.  Check out the demos in the online manual.  The revolute joint is similar, although you probably don't want the rotation.

Also, why are you using a hexagon around your circle when you could just use a circle geom to detect collisions?  Couldn't you just create a larger circle than your body?  I could just be dense though.

Mar 16, 2009 at 2:58 PM
Very nice explanation and graphics MegaManZZ.

1. To me it seems like the proxyfield never rotate either? If that is the case, you just create your player body and make the player geometry and proxy geometry point to the player body. One body, two geometries. This way the proxy field will always follow the player and it will have the same rotation as the player. To remove that rotation you can set the MomentOfInertia to float.PositiveInfinity or create a FixedAngleLimitJoint (in the case you want it to rotate under some conditions).

2. You write: "There is only collision detection for the 'Proxy Field' via OnCollsion. It will not deflect off any object, only detect if there is a collison."

I'm not sure what you mean by that, but you should set the proxyfield to have CollisionsResponseEnabled to false. This way it will never interact with other objects, only detect collisions.

3. This is possible by doing what Jerky said. Use the ContactList returned from the OnCollision event. It contains the contacts (vertices) that the geometries have and their position.
Mar 17, 2009 at 12:21 AM
Edited Mar 17, 2009 at 12:27 AM
thanks for helping me out guys but im still having trouble implementing this feature, although im pretty sure this is just what i need.
Lets say i need to do the following.
bool topLeftProxy          = false;
bool topProxy                = false;
bool topRightProxy        = false;
bool bottomRightProxy  = false;
bool bottomProxy          = false;
bool bottomLeftProxy    = false;

yourGeom.OnCollision += MyOnCollisionMethod;

private bool MyOnCollisionMethod(Geom geom1, Geom geom2, ContactList list)
         (change the appropriate bool element currently colliding to true);

at the top of the code are bool elements that would represent each of the six verts of a hexagon object. How could I change them to true if collision if the particular items are detected. And no there is no rotation on the proxyGeom.
Mar 17, 2009 at 3:52 AM
I dont have any code in hand, but if you do some calculation to check positions on vertices of contact lists versus the actual vertex positions then set the appropriate bool to true that might work?