detect collision of two bodies by side

Hi. As I see, contact listener detects collision by points. I would like to detect if two bodies collide by their sides, not points or sharp edges.
Is this possible?
Use multiple shapes/fixtures for your body--the sides being sensors whose userData whose userdata you can set to some string like 'wall'...then in the contact listener see if the userdata of the colliding shapes/fixtures is 'wall'.

Not sure how or if this can be done in 2.0 ..but it's very straightforward to do in 2.1 by this method.
I don't understand this question. Unless a shape is a circle, there will always points and edges involved.
Maybe you could draw a picture?
e96 wrote:
Use multiple shapes/fixtures for your body--the sides being sensors whose userData whose userdata you can set to some string like 'wall'...then in the contact listener see if the userdata of the colliding shapes/fixtures is 'wall'.

Not sure how or if this can be done in 2.0 ..but it's very straightforward to do in 2.1 by this method.


I am using 2.1a, but this method isn't optimal, for example it still detects contacts with sharp edges.

irresistible force wrote:
Maybe you could draw a picture?


Sure, here it is:
Image
aaah...
I think the only way you could do that is to look at the edges of the colliding shapes yourself, and check if they have edges which are near-parallel and very close together, or if you know the shapes will be rectangular you could just check the current angle of them for similarity.
How can I iterate over edges of shape ? Or how do I check if two shapes are perpendicular? I need to get angle from linearVelocity?
From the fixture you can get the body, and from the body you can get the angle. If your shapes are both rectangles set up so that their sides were along the same axes then you can just compare the current angle of their bodies to see how close they are rotation-wise. Remember that for rectangles the sides will align every 90 degrees though 😉

For a generic polygon it's not so easy, you might have to change the box2d code so you can get the points of the shape, or you could save the point information in user data when you create it. You will also have to make sure you are comparing the right edges to each other too... could be tricky.

What are you making?
Got the point, I expect I will use in game box, triangle and polygon shapes so I am searching for universal solution.
Manually adding data to userData should do the trick. 🙂

In 2.1a I don't see a method persist in ContactListener. I would like to check if shapes are perpendicular to each other when contact persists, not on begin or end. Is this possible?

How to keep count of points that collide with other fixture? I am adding counter on Begin, and substracting on End and I can't get past 1 count. Why?
When two fixtures collide each other by other corner, it is counting as new contact therefore triggering EndContact before new BeginContact?
You need to look at the contact manifold. the manifold should have something like "pointCount". This will be 2 for the side / side collisions you are looking for. It's been a while since I looked at the native port but this should be in there somewhere.
Ok, should I check that in PreSolve or PostSolve?
I tried in Pre and it works, but sometimes 2 counts are returned when two bodies aren't contacting exactly by edges - the gap between them and angle is very small though.
What should I do to get exact edge contact detection?

Original thread: https://box2d.org/forum/viewtopic.php?t=5836