-
-
Notifications
You must be signed in to change notification settings - Fork 21.3k
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
Fix separating axes for 3D cylinder-face collisions #89960
Fix separating axes for 3D cylinder-face collisions #89960
Conversation
Great find! This fixes cylinder-trimesh collisions (cylinder against The issue #57476 that you originally linked (which is about cylinder-cylinder) is not fixed as far as I can tell; probably you were referring to some other cases mentioned in the comments on that issue. Here is an explanation why your fix works, for completeness: When testing for collisions between a cylinder and a triangle face, the SAT solver constructs several axes in 3D space, and for each axis it checks if it is a separating axis. Three of the axes that are supposed to be constructed are those pointing specifically from the cylinder's tubular surface to the points of the triangle, in the normal direction of the tubular surface. If a point P belongs to the plane that (i) passes through the cylinder's center and (ii) is normal to the cylinder's axis, then the axis-to-test is given by the direction vector from the cylinder's center to the point P (which will be perpendicular to the cylinder's tubular surface). If you move the point P along the direction of the cylinder's axis, then the axis-to-test (normal to the tubular surface, pointing at P) does not change, so in general you can project P to the aforementioned plane, and take the direction vector from the center of the cylinder to the projection of P on the plane. The issue was that the plane was constructed in coordinates centered at the cylinder's origin, so the Please apply the change suggested by @AThousandShips (and squash your commits), and then we can happily merge this. Edit: Please also change the first line of the commit message to the current title of the PR. The same issue seems to affect box-cylinder here: godot/servers/physics_3d/godot_collision_solver_3d_sat.cpp Lines 1330 to 1331 in 29b3d9e
As well as box-capsule here: godot/servers/physics_3d/godot_collision_solver_3d_sat.cpp Lines 1216 to 1222 in 29b3d9e
Please try testing and fixing those in the same way, if you have time (in this PR or another, with me as coauthor if you like). |
2754083
to
3788ddf
Compare
When checking for lateral surfaces of a cylinder against the points on a face, the axis projection does not remove the cylinder position. This results in the axis pointing to the wrong direction and reports collisions when there shouldn't be.
3788ddf
to
3f69af9
Compare
Thanks for the thorough explanation @rburing. I've made the changes per your suggestion. I will have a look a the other cases as well. I need some time to setup a test scene to reproduce the bugs so I will open a new PR if I'll fix them. |
Thanks! And congrats for your first merged Godot contribution 🎉 |
Thanks, happy to help 🥳 |
Cherry-picked for 4.2.2. |
I'm not a 100% this is the correct fix, I would appreciate if someone who knows the SAT equations or the physics system better would look it over. However as far as I can see this fixes the issue and does not cause any additional ones (as far as I can see :) )
I think the issue is because when checking for lateral surfaces of a cylinder against the points on a face, the axis projection does not remove the cylinder position. This results in the axis pointing to the wrong direction and reports collisions when there shouldn't be.
I included a test scene to exhibit the issue and fix
sandbox.zip
Physics squad edit: