New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
b2EPCollider::Collide method doesn't use m_radius of the shapes #428
Comments
In a sort of similar problem, b2CollidePolygon.cpp in function |
@MelvMay Thank you for bringing a problem with |
So I'm the guy who integrates 2D physics into Unity: Various stuff here. So, the capsule contribution above highlights the problem as it uses a single edge polygon with a radius as a capsule. This works, as you referred to, when doing edge/circle ( This is a shame because the As an example, create two |
@MelvMay Thanks for the clarification! This is indeed the problem that I was thinking you could have meant. I've actually been working on the collision code to add handling like we're talking about. I have the code changes necessary for the polygon-circle manifold calculating function done and I'm working on the changes for the remaining collision-pair types. I've also created a separate issue (issue #429) for this other problem. |
I'd be interested in seeing your solution. My code for CapsuleCollider2D inside Unity is a little convoluted and I'll be working on making it more efficient in the new year for Unity 5.6 but I'd be interested to see what you've come up with. I can only say that if it's better than what I've got then, with your permission, I'd have no problem switching to your code, with the proper attribution of course! As an aside, I did have an 'Edge Radius' in 5.6 however it's been removed due to the problems with poly/poly + radius above. Various other things have stopped me working on this unfortunately but again, it stems from the same issue above. |
@MelvMay I have the code working now for this in my dev branch (prior to commit dfd51ec). Sorry it took me till now. I've been working on another thing that I wanted to change in the code but got this done now as a side-effect of sorts of trying to make the other change. Here's a screen shot of it: This picture shows a circles-type collision occurring between a triangle and a capsule. These are implemented both as polygons (the triangle having 3 vertices and the capsule having 2). Unfortunately I believe it will take some translation and temporal Kung-fu of my code to recognize where things are getting done for this. When I developed the code, I found it preferable to generalize the polygon shape type to handle two or one vertices rather than create yet another new shape type. And this code is still very much in flux. If you want to see it though, look around in Box2D/Collision/CollideShapes.cpp, specifically from the Algorithmically speaking, I achieved this solution essentially by removing the addition of the skin radius total from the incident edge clipping and then checked for the vertices being within that total radius of each other when edge collision wasn't detected. If the vertices were within the total radius of each other, then a 'e_circles' type manifold is returned from the manifold calculating code (instead of the face type manifold that would have formerly been returned). |
I worked on this over xmas and it sounds similar to what I came up with by removing the 'side offsets' part then checking the vertex. I'll check out your code this week. I very much appreciate you getting back to me, thanks! |
Hi Guys, sorry I'm late to respond. The radius exists for polygonal shapes only to support continuous collision detection. There is no support for rounded polygons. In my experience it is best to implement capsule collision directly and handle all the different cases with new collision functions. I'm making the change suggested in b2EPCollider::Collide, but that is just for correctness and does not provide new capability. I've also added this comment to b2Shape::m_radius: |
@MelvMay-Unity which way is currently used in Unity? Do you use edge radius or recommended separate capsule shape? |
The collision manifold calculating code of the
b2EPCollider::Collide
method in b2CollideEdge.cpp (as of commit 374664b from Jun 19, 2016) calculates the total radius on line 435 as2 * b2_polygonRadius
. Ab2EdgeShape
instance or ab2PolygonShape
instance can have a differentm_radius
thanb2_polygonRadius
however.For shapes having
m_radius
settings greater thanb2_polygonRadius
, this results in a dynamic polygon body in a gravitational world that would otherwise sit atop the edge repeatedly bouncing up and down from the edge.Everything appears to work correctly if the total radius calculation is changed to be the sum of the m_radius values of each shape.
The text was updated successfully, but these errors were encountered: