Jul 2, 2012 at 7:45 AM
Edited Jul 2, 2012 at 7:48 AM
This is a revisit of
I've now managed to rig my own Collider type into Farseer, but I'm experiencing a minor problem. When I set a polygon (such as the box) down on top of the tile map, it keeps getting pushed out and separating, then goes back to being in contact. The difference
is almost not even visible, however, when a polygon sits on top of say a static edge, it sits there just fine with no problem.
Now, I am definitely no expert on physics, so I had to do some finagling to get the contact manifold working the way I wanted it. Currently, for polygons I test each point to see if it's within the polygon, and then I find the shortest (minimum) distance
from each point to any edge, and take the maximum distance of all points and use whatever point that is as my point of contact (basically the Minimum Translational Distance). It works quite well, although technically this is not a tile map, but rather a point
map, but the spacing between points is so small that it shouldn't be a problem.
Last time I worked with a physics manifold, I had to output penetration distance and it was used as a Baumgart parameter (error factor) for constraints, but I don't see anything like that here (I thought maybe I was doing something that was causing my object
to get pushed out too much!).
I also have it working for circles, but for some reason the point of contact always had to be Zero. Lastly, I am not doing multiple points of contact yet; I really couldn't figure out how it worked, because I tried it and ended up with something crazy.
Tile Map 1
Tile Map 2
So, any idea why my object keeps separating and colliding over and over, but this doesn't happen for say a polygon and a static edge?
Thanks a million!
<Update> - I thought maybe it was happening because of the 1 point of contact (bouncing from side to side). I set FixedRotation to true, and it still happens.
Jul 2, 2012 at 11:04 PM
Edited Jul 2, 2012 at 11:17 PM
This seems like a tough issue to tackle. You might want help from someone who has actually made a physics engine and not just using it like me. Perhaps the Box2D forums or Bullet forums will serve you better if no one here chips in.
At first glance, though, it seems to me this is quite expected behaviour. The point is that the manifold points are pretty random in the case of polygons. They are by no means optimal or representative. Just a means to an end - to find *a* plane (one
of many possible) that would separate the polygons if they are moved along the normals. You can also look at Bullet physics - I remember reading a few posts on their forum with some info like number of contact points etc.
What this actually might mean in reality is that with the solver being iterative a polygon actually moves a bit up and down as collisions are resolved and new ones occur. This is usually not visible to a user but I can understand it might be a problem if
you need precise info. Circles and Edge shapes give different manifolds (exact mathematical solution? optimal?) so that might explain the different behaviour.
Some related info:
This is a bit out of my league too, but I would guess that it's due to only taking one point into account. The impulse applied at the most overlapping point is only concerned about correcting its own overlap, and it doesn't care about whether it might be
making the overlap worse somewhere else. The classic example is a ball sitting in a v-shaped 'hole' made of two straight edges - if you can only apply an impulse to push the ball away from one wall at a time, you will always be pushing it into the
other wall. It can only be resolved by taking both sides into account together and applying an impulse upwards.
To make a manifold to simultaneously handle two of these points could be very tricky - I can't even think how you would know which two points should be used. Let's say the worst overlapping point penetrates by 1 unit, and over on the other side of the box
there is another point which penetrates by 0.2. But wait, all the neighboring points of the worst one are also penetrating by nearly 1 unit as well... how can you make a sensible manifold from this? I think this is the reason Box2D only does collision between
Can you not just make a bunch of normal circle fixtures to represent this grid? If they never move they could be all on the same body, or if you need them to move they could each be on their own kinematic body. Then you would get the benefit of the dynamic